This post originated from an RSS feed registered with Python Buzz
by Richard Jones.
|
Original Post: Handy debugging snippets
Feed Title: Richard's stuff
Feed URL: http://mechanicalcat.net/cgi-bin/log?flav=rss
Feed Description: Stuff I'm interested in
|
Latest Python Buzz Posts
Latest Python Buzz Posts by Richard Jones
Latest Posts From Richard's stuff
|
|
Advertisement
|
From Anthony,
btw, for debugging purposes, I recommend the following snippet:
import traceback
def compact_stack():
stack = traceback.extract_stack()
stack = [ '%s:%d'%(x[0], x[1]) for x in stack ]
return "Stack\n" + "\n".join(stack)
I've also used the following as a generic debug() call in Zope code
(though any logging package could replace zLOG here):
def debug(*args):
module, line, function, info = traceback.extract_stack()[-2]
if len(args) == 1:
s = pprint.pformat(args[0])
else:
s = pprint.pformat(args)
file = os.path.split(module)
LOG('\n%s\n in %s, line %s, debug info:'%(module, function, line),
INFO, '\n'+s)
That traceback.extract_stack
function is so useful :)
Read: Handy debugging snippets