Rick Hurst Web Developer in Bristol, UK

Menu

pdb and zdb – debuggers for python and zope

(updated 10/6/2008 – to reflect Dan’s corrections below)
pdb has long been on my radar, but I had kind of dismissed it as something for “proper” programmers, rather than a web monkey like myself. However, i’m pleased to say i’ve actually finally used it during some plone development! The trick (for me) involves running the plone site in foreground mode so you can see messages in a terminal, and then with pdb you can interact with it. In your python script you need to add:-

import pdb
pdb.set_trace()

when the script reaches this set_trace() statement, you get a pdb prompt in the terminal allowing you to interact with the script and it’s variables at that point. e.g. print myvar to get the value of a variable or myvar.__class__ to find out what type of variable it is. You can also use ‘n’ to step through the script or ‘c’ to continue to the end.

Up until this point I relied on adding print statements in the scripts to try to work out what was happening – a bit like i’ve done for all my web dev over the years – a common mistake for me is to leave these in, then get confused clients asking why the word “here” and “foo=[1]” keeps appearing on their website!

You can also use a similar tool to debug zope skin scripts. This uses a similar principle – run your site in foreground mode, and you can interact with the skin script from the set_trace statement.

from Products.zdb import set_trace
set_trace()

archived comments

Actually… it’s:

import pdb
pdb.set_trace()

zdb’s incantation is:

from Products.zdb import set_trace
set_trace()

/pedant

Dan Fairs 2008-06-09 16:57:49