我想子类化该list
类型并让切片返回后代类型的对象,但是它返回一个list
. 执行此操作的最少代码方式是什么?
如果没有一种简洁的方法,我将在内部包含一个稍微混乱但并非不合理的列表。
到目前为止我的代码:
class Channel(list):
sample_rate = 0
def __init__(self, sample_rate, label=u"", data=[]):
list.__init__(self,data)
self.sample_rate = sample_rate
self.label = label
@property
def nyquist_rate(self):
return float(self.sample_rate) / 2.0