Getting class name
mackstann
mack at incise.org
Fri Aug 29 15:51:34 EDT 2003
On Fri, Aug 29, 2003 at 09:26:47PM +0200, Irmen de Jong wrote:
> Or if you're using Python 2.3+ :
>
> >>> import inspect
> >>> def foo():
> ... return inspect.getframeinfo(inspect.currentframe())[2]
> ...
> >>> foo()
> 'foo'
> >>>
The following works for me in python 2.2:
>>> import traceback
>>> def foo():
... return traceback.extract_stack()[-1][2]
...
>>> foo()
'foo'
Also, doing len() on traceback.extract_stack() can give you an idea of
what "depth" you're at (of nested function calls).
--
m a c k s t a n n mack @ incise.org http://incise.org
Troubled day for virgins over 16 who are beautiful, wealthy, and live
in eucalyptus trees.
More information about the Python-list
mailing list