It's nice that Python displays a stack trace when an error occurs, but I'm not sure how many minutes it's wrong.
So make a note of how to debug with a Python script.
The following site summarized it very easily, but since there was no detailed explanation about debugging terms, I will add a supplementary explanation. http://racchai.hatenablog.com/entry/2016/05/30/070000
Debugging in Python uses the pdb module.
Easy to use. Just add the line below just before the dubious place.
import pdb; pdb.set_trace()
If you execute the script in this state, the interactive debugger will start at that location.
After that, just type the step
command and execute it line by line. (This is called ** step-in **)
Also, if you want to see the contents of a variable while debugging, use the p
command. You can check the value stored in hoge
by typing p hoge
.
command | Description | Remarks |
---|---|---|
s(tep) | Step in (execute line by line) | If you enter a function during processing, it will stop line by line in the function as well. |
n(ext) | Step over (executed line by line) | Execute one line at once including function call |
r(eturn) | Step out (execute in function units) | Execute until the runtime function is returned |
l(ist) | View source before and after current line | |
a(rgs) | Show the arguments of the current function | |
p | Check the value of a variable | p hoge Use like |
c(ontinue) | Run to next breakpoint |
http://docs.python.jp/2/library/pdb.html http://racchai.hatenablog.com/entry/2016/05/30/070000
Recommended Posts