function name
Peter Otten
__peter__ at web.de
Wed Apr 28 15:03:36 EDT 2010
Richard Lamboj wrote:
> is there any way to get the name from the actual called function, so that
> the function knows its own name?
>>> import sys
>>> def my_name():
... return sys._getframe(1).f_code.co_name
...
>>> def rumpelstilzchen():
... print u"Ach, wie gut dass niemand weiß, dass ich", my_name().title(), u"heiß"
...
>>> rumpelstilzchen()
Ach, wie gut dass niemand weiß, dass ich Rumpelstilzchen heiß
Peter
More information about the Python-list
mailing list