getting current call stack

Alex Martelli aleaxit at yahoo.com
Thu Jun 7 18:40:23 CEST 2001


"Olaf Meyer" <olaf.meyer at nokia.com> wrote in message
news:yuk98zj45ljw.fsf at manta.europe.nokia.com...
> Is there any way to determine the current call stack from a
method/function?

In Python 2.1, sys._getframe([depth]):
Return a frame object from the call stack. If optional integer depth is
given, return the frame object that many calls below the top of the stack.
If that is deeper than the call stack, ValueError is raised. The default for
depth is zero, returning the frame at the top of the call stack.
This function should be used for internal and specialized purposes only.

In older versions, a try/catch and lot of play with
the traceback object lets you do similar things, but
it's even more obviously 'black magic':-)


Alex







More information about the Python-list mailing list