Paulo said:
Em 23-08-2010 04:30, James Mills escreveu:
I did it before posting ...
The "explanation" is not very clear. It is more like "how to use it".
Thanks anyway.
A very naive approach:
Instance methodes modify/use the instance. They requires a reference to
the instance as first parameter (self)
class Foo:
def foo(self):
print self.instanceAttribute
Class methodes modify/use the class. They require a class as parameter (cls)
class Foo:
occurrences = 0
@classmethod
def foo(cls):
print "Number of %s occurrences : %s" % (cls.__name__,
cls.occurrences)
Static methods neither use a class nor an instance, thus require no
parameter. In that case, the class acts like a namespace (<~>container):
class Foo:
@staticmethod
def sayHello():
print "Hello"
Foo.sayHello()
Cheers,
JM