看看这段代码plz:有规则,在每一个实例中,oldets都必须刷新,Live是一个抽象类class Live(object):
_the_oldest = 0
def __init__(self,age,name):
self.age=age
self.name=name
@classmethod
def the_oldest(cls):
if Live._the_oldest < cls.age:
Live._the_oldest=cls.age
@staticmethod
def Print():
print(Live._the_oldest)
class Dog(Live):
def __init__(self,name,age):
super().__init__(age,name)
super().the_oldest()
class Cat(Live):
def __init__(self,name,age):
super().__init__(age,name)
super().the_oldest()
出现错误:
^{pr2}$
我更改了代码,但没有任何更改:class Live(object):
_the_oldest = 0
def __init__(self):
the_oldets(self)
@classmethod
def the_oldets(cls):
if Live._the_oldest < cls.age:
Live._the_oldest=cls.age
@staticmethod
def Print():
print(Live._the_oldest)
class Dog(Live):
def __init__(self,name,age):
self.age=age
self.name=name
class Cat(Live):
def __init__(self,name,age):
self.age=age
self.name=name
结果:>>> db=Dog('doberman',12)
>>> db.the_oldets()
AttributeError: type object 'Dog' has no attribute 'age'
为什么会这样!?怎么解决呢?在