introspection?

David Bolen db3l at fitlinxx.com
Thu Aug 19 21:12:35 CEST 2004


Roman Suzi <rnd at onego.ru> writes:

> I am using different approach to introspection of Python
> functions and methods (not all available info output,
> only name of the previously called function/method).
> I am not sure if this is better than getting sys._getframe()
> or not, at least it doesn't use undescore methods ;-)
> and "knowns" about all invocation history at once,
> could even show source code, etc.

Note that for Python 2.1+ you can use the inspect module's
"currentframe" method to obtain your current frame in lieu of
sys._getframe(), if you prefer a more documented approach.

I believe you should also be able to work your way back up the call
chain using the f_back field within any given frame object if you want
to.

-- David



More information about the Python-list mailing list