Debugging Python

Peter Hansen peter at engcorp.com
Fri Jan 9 09:42:04 EST 2004


Ashley Lloyd wrote:
> 
> What do people generally use to debug their Python programs? I haven't seen
> anything out there that walks through the code, but perhaps I'm looking in
> the wrong places?

When I need to, which is rare, I either use print statements (a very
solid technology dating from, oh, last century sometime ;-), or the 
Python debugger module: pdb.  

Actually, all I ever do with pdb is this:

   # this is just before the code that I think is failing
   import pdb
   pdb.set_trace()

   # code that I'm about to trace through goes here


And about the only features of pdb I've had to use are "r", "n", and
the ability to inspect arbitrary variables.

I'm not sure about others, but when I design and code using test-driven 
development (TDD), I tend not to need to debug almost ever.  The need
to debug is usually when you aren't sure where a typo, or logic error,
or other mistake has actually occurred.  When using TDD, it's exceedingly
rare that when a test fails, I don't know exactly where the problem is
without having to resort to traditional (slow, tedious, annoying) debugging.

-Peter



More information about the Python-list mailing list