(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:-
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=” 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