I need to add more values to a list of WSHandler connections (Tornado, Python). I’m adding the connection to a list like so self.connections.append(self), but I need to add more information, like self.connections.append({'id': self, 'keyword' : ''}) (and later find the current self id and replace the keyword.)
When I try to add to the list based on self object (like self.connections[self].filter = 'keyword'), I get TypeError: list indices must be integers, not WSHandler.
So how can I do this?
Edit: Managed to find the right object like so:
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
Now, how do I remove the whole dict from connections ? self.connections.remove(self) no longer works, of course.
For this use case, you do not need a list of connections. It may be easier to store this in the object itself. Simply use
self.filter = 'keyword'.Otherwise:
Or, if you favour brevity over clarity:
To remove, use: