Re: Debugging Python

From: Harry George (harry.g.george_at_boeing.com)
Date: 01/09/04


Date: Fri, 9 Jan 2004 10:29:46 GMT

Peter Hansen <peter@engcorp.com> writes:

> 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

Interesting. A python newbie asked me the same thing yesterday and I
told him almost exactly what you said: If you are doing test-based
(whether or not it is with someojne else and thus Agile), you don't
get into those grim debug sessions that are part of life in C/C++
land.

Actually what I said was something like

"If you don't make mistakes, you don't need a debugger. The way to
avoid mistakes is to test everytime you edit a line or two of code.

"If you need to, use my homegrown debug statements (which print the
module and method/function name, the message, and then flush). If you
really get stuck, there is a debugger, but typically you just need
debuggers to solve memory problems. Python mistakes tend to be much
higher level, and pretty obvious once you see the data values."

-- 
harry.g.george@boeing.com
6-6M31 Knowledge Management
Phone: (425) 342-5601


Relevant Pages

  • Re: How to connect to children process
    ... Main problem is amount of manual operations required per debug cycle. ... connection to DLL with debugger takes sensible amount of time and manual ... Is the main problem that the debugger keeps symbols file loaded ... AFAIK that's how VS2003 debugger works, but WinDbg should usually ...
    (microsoft.public.vsnet.debugging)
  • Re: Need Help Debugging
    ... you should use straight and plain ADPlus.VBS from the debugger package. ... debug info loaded, etc... ... does that avoid using the stack ?!? ... which is our custom CRITICAL_SECTION class. ...
    (microsoft.public.win32.programmer.kernel)
  • gnome-settings-daemon crashed twice
    ... To debug your program, run it with the --sync command line ... backtrace from your debugger if you break on the gdk_x_errorfunction.) ...
    (GNOME)
  • Re: DesignBAIS/Dave Bryant
    ... As Tony says you can also "debug" your code in the DB app (browser ... form of tcl access and are able to enter the native debugger anyway. ... i could enter the debugger on their public internet site they would ... Not all Visage applications are deployed to Public internet sites. ...
    (comp.databases.pick)
  • Re: SUnit disappointment
    ... I always press the 'Debug' button in the SUnitBrowser when I'm ... For example when examining a failure in the debugger rather ... I'll often be able to fix the failure in my second ... > Equals verify: object printString with: 'test' ...
    (comp.lang.smalltalk.dolphin)