name of the current function ?

Denis S. Otkidach ods at fep.ru
Sat Apr 27 09:33:46 EDT 2002


On Sat, 27 Apr 2002, Solveig Wiesmayr wrote:

SW> I would like to get the name 'my_name' of the current
SW> function to pass it
SW> to some other (debugging-) function.

>>> import sys
>>> def my_name():
...     return sys._getframe(1).f_code.co_name
...
>>> my_name()
'?'
>>> def f():
...     return my_name()
...
>>> f()
'f'







More information about the Python-list mailing list