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).
--
http://mail.python.org/mailman/listinfo/python-list