Inheriting dictionary

Hendrik van Rooyen hendrik at microcorp.co.za
Wed Aug 19 09:24:13 CEST 2009


On Tuesday 18 August 2009 21:44:55 Pavel Panchekha wrote:
> I want a dictionary that will transparently "inherit" from a parent
> dictionary. So, for example:
>
> """
> a = InheritDict({1: "one", 2: "two", 4: "four"})
> b = InheritDict({3: "three", 4: "foobar"}, inherit_from=a)
>
> a[1] # "one"
> a[4] # "four"
> b[1] # "one"
> b[3] # "three"
> b[4] # "foobar"
> """
>
> I've written something like this in Python already, but I'm wondering
> if something like this already exists, preferably written in C, for
> speed.

Its not inheritance, but have you looked at the update method?

-Hendrik



More information about the Python-list mailing list