我有一个奇怪的问题。我知道在 Python 中,kwargs 遵循 args,所以我检查了它,这不是问题。这是什么问题:
美好的:
def __init__(self, sample_rate, label=u"", data=[] ):
TypeError:__init__()
为关键字参数“数据”获取了多个值:
def __init__(self, sample_rate, data=[], label=u""):
引发错误的调用行如下所示:
def __getslice__(self, start, stop):
return Channel(self.sample_rate, self.label, data=list.__getslice__(self,start,stop))
完整代码:
class Channel(list):
sample_rate = 0
def __init__(self, sample_rate, data=[], label=u"" ):
list.__init__(self,data)
self.sample_rate = sample_rate
self.label = label
@property
def nyquist_rate(self):
return float(self.sample_rate) / 2.0
def __getslice__(self, start, stop):
return Channel(self.sample_rate, self.label, data=list.__getslice__(self,start,stop))
谢谢!