your favorite debugging tool?

Robert Kern robert.kern at
Sun Aug 23 09:54:31 CEST 2009

On 2009-08-22 07:25 AM, Esmail wrote:
> Hi all,
> What is your favorite tool to help you debug your
> code? I've been getting along with 'print' statements
> but that is getting old and somewhat cumbersome.
> I'm primarily interested in utilities for Linux (but
> if you have recommendations for Windows, I'll take
> them too :)
> I use emacs as my primary development environment, FWIW.
> Someone mentioned winpdb .. anyone have experience/comments
> on this? Others?

I am frequently in the IPython interactive prompt for testing out stuff and even 
as the main way of running my code. It has a nice feature that when you get a 
traceback, you can open up pdb post-mortem.

In [8]: def f(x):
    ...:     y = 1 / x
    ...:     return y

In [9]: f(1)
Out[9]: 1

In [10]: f(0)
ZeroDivisionError                         Traceback (most recent call last)

/Users/rkern/<ipython console> in <module>()

/Users/rkern/<ipython console> in f(x)

ZeroDivisionError: integer division or modulo by zero

In [11]: %debug
 > <ipython console>(2)f()

ipdb> print x

I have a little function that I've been using recently to print out the function 
I am currently in along with the arguments:

def whereami():
     """ Print the current function call.

     import kerntrace;kerntrace.whereami()
     import inspect
     frame = inspect.currentframe(1)
     args, varargs, varkw, f_locals = inspect.getargvalues(frame)
     if args[:1] == ['self']:
         del args[0]
     print '%s%s' % (frame.f_code.co_name, inspect.formatargvalues(args, varargs,
         varkw, f_locals))

I think pdb is okay, but I am looking forward to pydbgr's completion.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list