In Python 1.1 and later there's a standard module "traceback" which
helps by printing a stack trace exactly like the interpreter does.
You could put this at the end of your scripts (the function "main()"
is the script's main function):
if __name__ == '__main__': # Only do this when run as a script
import sys, traceback # Be prepared!
try:
main()
except SystemError, sts: # main() called sys.exit(sts)
sys.exit(sts)
except:
print "\n<XMP>" # Turn off HTML parsing
traceback.print_exc() # Print stack trace
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>