[Zope] Debugging Python scripts

Small Business Services toolkit at magma.ca
Sat Mar 20 15:21:25 EST 2004


From: "John Poltorak" <jp at warpix.org>
> Can anyone suggest how I can include some debugging in a Python script?
>
> I don't suppose there is any way to single-step through a program is
> there?

Not that I have discovered - I hope someone else can prove me wrong!

However, you can wrap your entire script in a 'try/except' and use a list
variable to collect debug info along the way and then print it out.

Eg.

try:
  debuglist = []
  some code
  debuglist.append('at point 1, somevar='+somevar)
  some more code
  debuglist.append('at point 2, anothervar='+anothervar)

except:
  return debuglist


Note: if you are using the 'Test' (ie. click on the Test tab while you are
editing the script within the ZMI) instead of 'return debuglist' use 'print
debuglist'

HTH

Jonathan




More information about the Zope mailing list