I'd like to access the name of a function from inside the function. My
first idea didn't work.

>>> def foo():
...     print func_name
...
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in foo
NameError: global name 'func_name' is not defined

My second attempt works but looks ugly.

>>> def foo():
...     import inspect
...     print inspect.stack()[0][3]
...
>>> foo()
foo

Is there a standard way of getting the name of a function from inside
the function?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to