As you know, python allows you to simply override the dict.__getitem__ method so that we can do something else in it when someone tries to extract some value from it.
I want to make code when one instance of the MyDict(dict) class is passed to the update method of another python dict instance. See below:
class MyDict(dict): def __getitem__(self, item): print "Doing some stuff here" return dict.__getitem__(self, item) d1 = MyDict({'1': 1, '2': 2}) d2 = {}
source share