basic inheritance question

Sean 'Shaleh' Perry shalehperry at home.com
Thu Sep 20 16:56:56 CEST 2001


> 
> class MyDict(UserDict):
>     "extend UserDict"
>      def __init__(self):
>           print 'Hello from MyDict.__init__'>>> import MyDict
> 

you do not call the parent's __init__, so the self.data member is not created.
Python does not call parent's constructors for you, it must be done explicitly.
Look at os.py in your python hierarchy for an example of UserDict's use.

> AttributeError: data
> 
> Can someone explain why I am not able to call the .keys() method of
> the MyDict even though it descends from UserDict?
> 




More information about the Python-list mailing list