The Artima Developer Community
Sponsored Link

Python Buzz Forum
Handy debugging snippets

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Richard Jones

Posts: 55
Nickname: rjones
Registered: Jul, 2003

Richard Jones is an over-eager Python Open Source programmer
Handy debugging snippets Posted: Jul 1, 2003 7:53 PM
Reply to this message Reply

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

Topic: Pondering a text format... Previous Topic   Next Topic Topic: sum

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use