我正在尝试从扩展类访问父成员变量。但是运行以下代码...
class Mother(object):
def __init__(self):
self._haircolor = "Brown"
class Child(Mother):
def __init__(self):
Mother.__init__(self)
def print_haircolor(self):
print Mother._haircolor
c = Child()
c.print_haircolor()
让我这个错误:
AttributeError: type object 'Mother' has no attribute '_haircolor'
我究竟做错了什么?
您正在混合类和实例属性。
print self._haircolor
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句