Getting method name from within the class method

yellowalienbaby at gmail.com yellowalienbaby at gmail.com
Wed Oct 18 17:38:12 EDT 2006


Mitko Haralanov wrote:
> I need to be able to get the name of the currently executed method
> within that method. I know that the method object does have the
> __name__ attribute but I know know how to access it from withing the
> method.
>
> Something like this:
>
> class A:
> ....
>     def a_method (self, this, that):
>          print <__name__>
>
> a = A ()
> a.a_method()
> 'a_method'
>
>
> Thanx for your help!

I'm not sure this is what you want, it seems redundant to me so i am
probably misunderstanding something, but I did;


>>> class test(object):
...  def a_method(self,this,that):
...   print self.a_method.__name__
...
>>> a=test()
>>> a.a_method('this','that')
a_method




More information about the Python-list mailing list