How to debug python code?

james.wondrasek at gmail.com james.wondrasek at gmail.com
Mon Apr 3 19:52:19 EDT 2006


I don't have an example, but what I do is insert:

import pdb
pdb.set_trace()

before the code that I think is causing the problem
(or that the traceback barfed at).

Then hit 'l' (lowercase L) to get a list of the code
which is being executed.

Use 'p' to look at variables. eg p some_local

Use 'n' to execute the current line of code
(doesn't follow method or function calls)

Use 's' to step through code, including following
function and method calls.

Finally, 'c' to continue execution as normal.

There are other options, but that should get you started.
And look at the article linked elsewhere in this thread.

pdb - because fencing off Alaska is too damn slow, binary
search or not.

jtm




More information about the Python-list mailing list