Re: Inheriting dictionary

2009-08-19 Thread Hendrik van Rooyen
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

Re: Inheriting dictionary

2009-08-18 Thread Simon Forman
On Tue, Aug 18, 2009 at 6:08 PM, Simon Forman wrote: > On Aug 18, 3:44 pm, 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:

Re: Inheriting dictionary

2009-08-18 Thread Simon Forman
On Aug 18, 3:44 pm, 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" >

Re: Inheriting dictionary

2009-08-18 Thread Pavel Panchekha
On Aug 18, 5:11 pm, "Jan Kaliszewski" wrote: > 18-08-2009 o 22:27:41 Nat Williams wrote: > > > > > On Tue, Aug 18, 2009 at 2:44 PM, Pavel Panchekha   > > wrote: > > >> I want a dictionary that will transparently "inherit" from a parent > >> dictionary. So, for example: > > >> """ > >> a = Inherit

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
18-08-2009 o 22:27:41 Nat Williams wrote: On Tue, Aug 18, 2009 at 2:44 PM, 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"},

Re: Inheriting dictionary

2009-08-18 Thread Pavel Panchekha
On Aug 18, 4:23 pm, "Jan Kaliszewski" wrote: > 18-08-2009 o 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"

Re: Inheriting dictionary

2009-08-18 Thread Nat Williams
On Tue, Aug 18, 2009 at 2:44 PM, 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[

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
18-08-2009 o 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"

Variables vs attributes [was Re: Inheriting dictionary attributes and manipulate them in subclasses]

2009-04-17 Thread Steven D'Aprano
On Fri, 17 Apr 2009 17:48:55 +0200, Diez B. Roggisch wrote: > No, because you are creating *classvariables* when declaring things like > this: ... > OTOH, when assigning to an instance, this will create an > *instance*-variable. Which is what If an integer variable is an integer, and a string va

Re: Inheriting dictionary attributes and manipulate them in subclasses

2009-04-17 Thread Diez B. Roggisch
Dominik Ruf wrote: > Hi, > > I just stumbled upon the following behaviour. class base(): > ... dic = {'1':'1', '2':'2'} > ... class child1(base): > ... def __init__(self): > ... self.dic.update({'1':'2'}) > ... class child2(base): > ... pass > ... c1 = child1()