我试图为从list继承的类定义一个init函数的“好方法”。下面是非常基本的代码(我只保留了必要的代码):
class measurementPoint(list) :
"""measurementPoint class : contains all the pairedMeasurement at a given temperature for a given channel"""
def __init__(self, item):
try:
assert isinstance(item,pairedMeasurement)
except AssertionError:
print("Wrong type for object " + str(item))
sys.exit(1)
super().__init__(self)
self.append(item)
初始化这样一个对象,难道没有比super().__init__
后跟append
更好的方法吗?我想应该有一个,但不知道怎么做
您可以将项作为iterable传递给
super().__init__
:相关问题 更多 >
编程相关推荐