Dictionary inheritance

Elmo Mäntynen elmo13 at jippii.fi
Sat Aug 13 17:55:45 EDT 2005


On Fri, 12 Aug 2005 12:44:11 -0700, Talin wrote:

> I want to make a dictionary that acts like a class, in other words, 
> supports inheritance: If you attempt to find a key that isn't present, 
> it searches a "base" dictionary, which in turn searches its base, and so on.
> 
> Now, I realize its fairly trivial to code something like this using 
> UserDict, but given that classes and modules already have this behavior, 
> is there some built-in type that already does this?
> 
> (This is for doing nested symbol tables and such.)
> 
> ---

You could always do:

class nestedDict(dict):
    ...



More information about the Python-list mailing list