getting the function name

Mathias Waack M.Waack at
Fri Sep 17 19:59:49 CEST 2004

beliavsky at wrote:

> Is there a way in Python to print the name of the function one is
> currently in?

>>> def f():
...   tb = traceback.extract_stack()
...   print tb[-1][2]
>>> f()

I'm using a more comfortable way by setting a global debug flag and
enabling tracing (see sys.settrace). This gives you the same feature
without adding code to each function. 


More information about the Python-list mailing list