Feed on
Posts
Comments

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’.


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

4 Responses to “use the python debugger!!”

  1. on 01 Oct 2007 at 2:04 pm Eric Brunson

    Very cool. I had no idea it was so easy. :-)

  2. [...] really trying to do is set breakpoints and debug your script, you should be looking at the python debugger [...]

  3. on 16 Aug 2009 at 10:14 pm sean

    If you don’t mind using Eclipse(with PyDev plugin), debugging is much easier – no modifying the source.

  4. on 29 Jul 2010 at 11:27 am juandesant

    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

Did I get this wrong? Let me know!

Trackback URI | Comments RSS