I have a class that contains a static dictionary:
class MyClass:
my_dict = {}
def __init__(self, name):
self.name = name
MyClass.my_dict[self.name] = []
def __call__(self, data):
MyClass.my_dict[self.name].append(data)
Whenever I want to update the dictionary, I have to use MyClass.my_dict[key]
, but I'd like the class itself to support item assignment so I can just use MyClass[key]
to do the same thing. Is there a way to do this? I'm using Python 2.7.