Debug python programs

Jeremy Jones zanesdad at bellsouth.net
Thu Sep 11 09:10:29 EDT 2003


* York (yorklee70 at yahoo.com) wrote:
> Hi, anybody,
> 
> Would you please recommend some good softwares/methods for 
> tracking/debugging python codes.
> 
> Thanks,
> York

You've got lots of options.

1) Your standard insertion of "print" statements throughout the code.  A
lot of times, this is good enough to get the job done.  I typically set an
instance variable named DEBUG for each class that I create (in __init__,
set self.DEBUG = 0 or 1).  Then I have lots of
if self.DEBUG:
    print "whatever" #insert debug statements here
It's not the most elegant thing, but man, has it come in handy when you
don't need a full-blown debugger.  (Segue into number 2)

2) Python comes with a pretty good debugger built in.  Here are the docs:
http://www.python.org/doc/current/lib/module-pdb.html

3) pychecker.  I know, I know, I know - it's not a debugger.  But if you
point it at your code, it'll inspect it and can help you uncover some
mistakes that can bite you in the rear.

4)  trace.py.  Never used it, but it's in the standard distribution now
under Tools/scripts.  (I'm including this line item since you mentioned
"tracking".  I guess this is what you mean?)

HTH


Jeremy Jones





More information about the Python-list mailing list