Python Class inheritence
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
subclass __init__ overrides superclass’s
号
1 2 3 4 5 6 7 8 9 10 11 12 | class A(): z = 'z it is' def __init__(self): self.a = 'a it is' class B(A): def __init__(self): self.b = 'b it is' b = B() print b.z # z it is print b.a # AttributeError: B instance has no attribute 'a' |
您需要显式地调用超类
B类中的
1 2 3 4 | class B(A): def __init__(self): A.__init__(self) self.b ="b it is" |