access the name of my method inside it
Steve Holden
steve at holdenweb.com
Wed Aug 1 07:01:42 EDT 2007
Marc 'BlackJack' Rintsch wrote:
> On Wed, 01 Aug 2007 09:06:42 +0000, james_027 wrote:
>
>> for example I have this method
>>
>> def my_method():
>> # do something
>>
>> # how do I get the name of this method which is my_method here?
>
> Why do you need this? There are ways but those are not really good for
> production code.
>
Maybe he wants to write a recursive method?
Once way is to call self.__calss__.mymethod(self). Ugly, isn't it?
>>> class p:
... def mymethod(self, n):
... if n <= 1:
... return 1
... else:
... return n * self.__class__.mymethod(self, n-1)
...
>>> pp = p()
>>> pp.mymethod(10)
3628800
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list