[Tutor] Class vs. Static Methods
chuck at freshsources.com
Tue Jun 21 23:58:09 CEST 2005
So is the main motivation for class methods so that you can have the
class object available? It seems you can have that anyway in a static
method by just asking. I'm sure there's a good reason for this, but I
haven't yet gotten to the point of mastery where I can see a need for
class methods (even after reading Martelli's Nutshell). I understand
the syntax issues - I just don't see the need yet.
Tuesday, June 21, 2005, 3:28:48 PM, you wrote:
C> On Tue, 21 Jun 2005 16:52:09 -0400, Chuck Allison wrote
C> (in article <10110159435.20050621145209 at freshsources.com>):
>> Sorry for the elementary question: I was wondering if someone could
>> explain the difference to me between class and static methods. Coming
>> from other languages, I'm used to static methods, but not "class
>> methods". Thanks.
C> Does this help (from the QR)?
C> Static methods : Use staticmethod(f) to make method f(x) static (unbound).
C> Class methods: like a static but takes the Class as 1st argument => Use f =
C> classmethod(f) to make method f(theClass, x) a class method.
C> The decorators @staticmethod and @classmethod replace more elegantly the
C> equivalent declarations f = staticmethod(f) and f = classmethod(f).
C> Lee C
C> Tutor maillist - Tutor at python.org
More information about the Tutor