dictionary inherit and method overriding

Christian Heimes lists at cheimes.de
Wed Jul 15 07:31:44 EDT 2009


fdb wrote:
> Hi all,
> 
> I need to extend and not replace the __getitem__ method of a dict class.
> 
> Here is sample the code:
> 
>>>> class myDict(dict):
> ....     def __getitem__(self, y):
> ....         print("Doing something")
> ....         dict.__getitem__(self, y)
> ....
>>>> a=myDict()
>>>> a["value"] = 1
>>>> print a["value"]
> None
> 
> As you see i get None instead of  1.
> 
> Any solutions?

How about returning the value? :]

Christian




More information about the Python-list mailing list