我有一个基类,一堆子类,对于这些子类的每一个,我都有另一组子子类。例如:
class BaseClass(object):
def __init__(self):
with open(config.txt) as f
self.config_array = f.readlines()
class FirstOrderSubClass(BaseClass):
def __init__(self, name):
self.name = name
class SecondOrderSubClass(FirstOrderSubClass):
def __init__(self, name, version):
self.name = name
self.version = version
super(SecondOrderSubClass, self).__init__(self.name)
# needed to access self.config_array
print self.config_array
我需要获取
SecondOrderSubClass
的__init__()
方法,以完成以下赋值:self.lines = self.config_array
。编辑:添加行
print self.config_array
。如果我运行代码,将会得到以下结果:TypeError: __getattr__() takes exactly 1 argument (2 given)
FirstOrderSubClass
中添加super(FirstOrderSubClass, self).__init__()
。 - Padraic Cunningham