Name of the function
Terry Reedy
tjreedy at udel.edu
Thu Jan 8 14:07:11 EST 2004
"anton muhin" <antonmuhin at rambler.ru> wrote in message
news:btjuct$84v33$1 at ID-217427.news.uni-berlin.de...
> Olaf Meding wrote:
> > I am looking for a way to get at the name of the function (while
> > executing code inside the function) without (!) knowing the name of
> > the function.
> >
> This seems to work:
>
> def foo():
> print inspect.currentframe().f_code.co_name
as does this ...
>>> def f(): print f.func_name
...
>>> f()
f
... as long as 'f' remains bound to that function in the same module, which
it will unless rebound either from within or without.
Terry J. Reedy
More information about the Python-list
mailing list