Extracting namespace of innermost frame in traceback

Jason Orendorff jason at jorendorff.com
Wed Jan 9 12:11:52 EST 2002


> Is it possible to extract the global namespace of the inner-most 
> frame of a 
> traceback stack?  I see that sys.exc_info()[2].tb_frame.f_globals 
> gives the 
> globals of the outer-most frame.  Is there something similar for the 
> inner-most?

import inspect

trace = inspect.trace()  # uses current exception
f, filename, lineno, fnname, linelist, n = trace[-1]
globals = f.f_globals

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list