On Wed, 01 Aug 2007 07:01:42 -0400, Steve Holden wrote:

> 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?

Ugly yes, unnecessary convoluted yes, solution no.  You typed `my_method`
in the source.  The OP wants to know how to avoid that.

>  >>> class p:
> ...   def mymethod(self, n):
> ...     if n <= 1:
> ...       return 1
> ...     else:
> ...       return n * self.__class__.mymethod(self, n-1)

Why not simply ``self.mymethod(n - 1)`` instead!?

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to