我與測量值的列表,如:「列表」對象沒有屬性「方法」
[[Measurements(100, 0.3)],
[Measurements(33, 0.5)]]
然後,我有一些標準的列表,其包含的測量列表:
[Criteria(999, [[Measurements(100, 0.3)],
[Measurements(33, 0.5)]])],
[Criteria(999, [[Measurements(150, 0.3)],
[Measurements(35, 0.5)]])]
最後,我想提供上述列表作爲輸入並執行代碼:
class Measurements():
def __init__(self, value, other):
self.value = value
self.other = other
class Criteria():
def __init__(self, new_value, measurements):
self.new_value = new_value
self.measurements = measurements
def method(self):
# Here, I am iterating through all measurements
# and replace the value according to criteria
for idx, x in enumerate(self.measurements):
if (self.measurements[idx].value > 20 and
self.measurements[idx].value < 110):
self.measurements[idx].value = self.new_value
return self.measurements
class Evaluate():
def __init__(self, criteria):
self.criteria = criteria
def execute(self):
criteria = self.criteria
# Here, I am iterating through all criteria
# and call the method from criteria
for i, c in enumerate(criteria):
c.method()
return c.measurements
def main():
criteria = [
[Criteria(999, [[Measurements(100, 0.3)],
[Measurements(33, 0.5)]])],
[Criteria(999, [[Measurements(150, 0.3)],
[Measurements(35, 0.5)]])]
]
obs = (Evaluate(criteria).execute())
if __name__ == "__main__":
main()
和我收到c.method() AttributeError: 'list' object has no attribute 'method'
我想我的結果是新的校正測量,所以:
[[Measurements(999, 0.3)],
[Measurements(999, 0.5)]],
[Measurements(150, 0.3)],
[Measurements(999, 0.5)]]
爲什麼你有嵌套的列表? 'C'是'[標準(999,...)]',在它的一個元件的列表,*不*'標準(999,...)'。 –
我有嵌套列表,因爲我會有很多標準,我想評估。 – George
那並不需要*嵌套*名單.. –