class A(object):
value = 5
@classmethod
def cls_fun(cls):
print('A.cls_fun', cls, cls.value)
def fun(self):
print('A.fun', self, self.value)
self.cls_fun()
class B(A):
value = 10
class C(A):
value = 15
@classmethod
def cls_fun(cls):
print('B.cls_fun', cls, cls.value)
def fun2(self):
print('B.fun2', self, self.value)
self.cls_fun()
class D(C):
value = 20
print('## A'); a = A(); a.cls_fun(); a.fun(); A.cls_fun()
print('## B'); b = B(); b.cls_fun(); b.fun(); B.cls_fun()
print('## C'); c = C(); c.cls_fun(); c.fun(); c.fun2(); C.cls_fun()
print('## D'); d = D(); d.cls_fun(); d.fun(); d.fun2(); D.cls_fun()
Item 27: classmethod
Posted by Logan Chien