Why there is a parameter named "self" for classmethod function?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon May 11 09:12:12 EDT 2009

Terry Reedy a écrit :
> Kurt Symanzik wrote:
>> But you might consider decorating the method as a static method 
>> instead since in your example you are not using the parameter at all.  
>> A static method would not require a parameter.
>> @staticmethod
>> def print_hello():
>>     print "hello"
> Functions that refer to neither the class nor an instance thereof can 
> usually be moved outside the class altogether.  Python is not Java.

Indeed. But there are a couple uses for staticmethods - one of them 
being polymorphic dispatch on the receiver object. And yes, I know, 
modules are objects too, but this is not always an option (legacy code, 
integration with a framework etc).

More information about the Python-list mailing list