who called a function?

Paul Rubin phr-n2001d at nightsong.com
Thu Nov 15 09:50:43 CET 2001


<kosh at aesaeion.com> writes:
> > Raise and catch an exception and examine the stack trace object.
> > --
> How do I step back through the trace stack object? Basically a few points
> would be nice or better yet a web page that shows some examples.

Hmm, I don't know of a web page but you can check the docs for 
traceback objects.  You could look at the python debugger (pdb) code
for an example but it's pretty straightforward how the frames are
chained together.  Hold on a sec... ok, here's something from one
of my programs.  Maybe it will help.

def dump_trace():
    ecl,e,trace=sys.exc_info()
    # print exception info
    print '@@ exception e=%s:%s' % \
          (e, [(a,getattr(e,a)) for a in dir(e)])
    while trace:
        co=trace.tb_frame.f_code
        print "@@trace: func=%s file=%s line=%d" \
              % (co.co_name, co.co_filename, trace.tb_lineno)
        trace = trace.tb_next



More information about the Python-list mailing list