What is class method?
elessar at nienna.org
Wed Aug 27 01:16:52 CEST 2008
Medardo Rodriguez (Merchise Group) wrote:
> On Tue, Aug 26, 2008 at 4:10 PM, Bruno Desthuilliers
> <bdesth.quelquechose at free.quelquepart.fr> wrote:
>> In Python, there's *no* relationship between classmethods and metaclasses.
> In OOP the concept of meta-class has everything to do with class
> methods, regardless if is in Python, SmallTalk or CLOSS. "classmethod"
> decorator it's just a syntax sugar structure to define them. There is
> no difference (conceptually) on "method1" and "method2":
> class MetaXClass(type):
> def Method1(self): pass
> class Xclass(object):
> __metaclass__ = MetaXClass
> def Method2(self): pass
>>> class MetaXClass(type):
... def method1(self): pass
>>> class XClass(object):
... __metaclass__ = MetaXClass
... def method2(self): pass
>>> xc = XClass()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'XClass' object has no attribute 'method1'
<bound method MetaXClass.method2 of <class '__main__.XClass'>>
More information about the Python-list