use the python debugger!!
March 16th, 2007 by Lawrence David
great gauss’ ghost, i had no idea how powerful the python debugger could be. basically, invoking the debugger allows you to stop your code at any point and investigate the current state of all variables in the environment. even better, the debugger allows you to try manipulating those variables; this allows you to break out of the terribly tedious, “update code -> insert print statement -> run -> update code” process. how i ever got by before discovering the debugger baffles me.
ok, enough yammering: to invoke the debugger all you need to do is import the pdb module:
import pdb
and at the line you’d like to jump into the code, insert:
pdb.set_trace()
you can quit the debugger using ‘q’.
Very cool. I had no idea it was so easy.
[...] really trying to do is set breakpoints and debug your script, you should be looking at the python debugger [...]
If you don’t mind using Eclipse(with PyDev plugin), debugging is much easier – no modifying the source.
I know it is a little late, but do you know that once you’ve hit the first pdb.set_trace(), you can use the b command to insert breakpoints?
More so: if you have a script in file.py, you can debug it without modifying it by invoking it with:
python -m pdb file.py