how can I get the name of a method inside it?

montyphyton at gmail.com montyphyton at gmail.com
Sun Jun 3 15:47:02 EDT 2007


> I would like to know if it's possible to retrieve the name of a method when
> you're inside it. For example, in the following script, I would like to
> assign _s so that it prints "you are in method1".
>
>
> ***************************************
> class Obj1:
>     def __init__(self):
>         ...
>
>     def method1(self):
>         _s = ???
>         print "you are in %s" % _s
>
> x = Obj1()
> x.method1()

i'm no expert on the subject, but AFAIK, there's no way to do this.
why not just print "you are in method1"?
what are you exactly trying to do?




More information about the Python-list mailing list