我需要向 WSHandler 连接列表(Tornado、Python)添加更多值。我正在将连接添加到这样的列表中 self.connections.append(self),但我需要添加更多信息,例如self.connections.append({'id': self, 'keyword' : ''})(稍后找到当前selfid 并替换关键字。)
当我尝试基于self对象(如self.connections[self].filter = 'keyword')添加到列表时,我得到TypeError: list indices must be integers, not WSHandler.
那么我该怎么做呢?
编辑:设法找到正确的对象,如下所示:
def on_message(self, message):
print message
for x in self.connections:
if x['id'] == self:
print 'found something'
x['keyword'] = message
print x['keyword']
print x
现在,如何从 dict 中删除整个 dict connections? self.connections.remove(self)不再工作,当然。