Hi, I have got a little problem with __setitem__ method. It works fine in single class, but if class member is instance of the same class method __setitem__ doesn't work on class member but on class. Here is an example:
Here is a class with __setitem__ method:
class MyClass:
attr = {}
def __setitem__(self, key, value):
self.attr[key] = value
and here i work with the class
>>> obj = MyClass()
>>> obj['key1'] = "value1"
>>> obj.attr
{'key1': 'value1'}
>>> obj.newinstance = MyClass()
>>> obj.newinstance.attr
{'key1': 'value1'}
>>> obj.newinstance['key1'] = "value2"
>>> obj.attr
{'key1': 'value2'}
>>>
as you see __setitem__ on newinstance works with self.attr from parent class. How can I hack this?