我脑子里有东西,但没有成功我有一个节点。在节点上,我们可以附加监视器。然后我有:
class Node:
def __init__(self):
self.components = []
self.monitors = []
class Monitor(object):
def __init__(self, platform_id):
self.platform_id = platform_id
我从服务器收到监视器列表,如果所有这些监视器未链接到节点,则它们必须是:
def get_or_create_monitor(self, monitors):
node_monitors = self.node.monitors
for m in monitors:
if m['id'] not in [m.platform_id for m in node_monitors]:
monitor = Monitor(m['id'])
node_monitors.append(monitor)
问题是我启动此功能时的控制台响应: TypeError: 'Monitor' object is not subscriptable
我哪里错了?我不能有类似 node.monitors = [, ] 的东西吗?