我有一个父类定义为:
class Alpha(X, Y, metaclass=abc.ABCMeta):
def __init__(self, time_series : pandas.Series):
super(Alpha, self).__init__()
我有它的儿童班:
class Beta(Alpha):
def __init__(self, returns: [daily_returns_object]):
super(Beta, self).__init__()
self.calibrate(returns)
我尝试根据以下内容创建Beta
对象:
#returns_list has been defined but is irrelevant here
beta_obj = Beta(returns_list)
我收到错误TypeError:__init__() missing one positional argument: 'time_series'
。因此,我写了beta_obj = Beta(time_series, returns_list)
,但后来得到错误TypeError:__init__() takes 2 positional arguments but 3 were given
。
答案 0 :(得分:1)
您在此处调用Alpha.__init__
方法:
super(Beta, self).__init__()
但是你没有在那里传递所需的time_series
参数。
如果这是Beta
也需要的参数,您需要将其添加到Beta.__init__
定义中,然后传递给它:
class Beta(Alpha):
def __init__(self, time_series: pandas.Series, returns: [daily_returns_object]):
super(Beta, self).__init__(time_series)
self.calibrate(returns)