Name of the function
anton muhin
antonmuhin at rambler.ru
Thu Jan 8 10:50:35 EST 2004
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.
>
> The code below works, but requires the name of the function. I am
> looking for a way to do the same w/o specifying the name of the
> function.
>
> def olaf():
> # requires name of the function
> print olaf.__name__
>
> # this does not work
> print self.__name__
This seems to work:
def foo():
print inspect.currentframe().f_code.co_name
regards,
anton.
More information about the Python-list
mailing list