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[4] # four b[1] # one

Inheriting dictionary

2009-08-18 Thread Pavel Panchekha
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

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
18-08-2009 o 21:44:55 Pavel Panchekha pavpanche...@gmail.com 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] #

Re: Inheriting dictionary

2009-08-18 Thread Nat Williams
On Tue, Aug 18, 2009 at 2:44 PM, Pavel Panchekha pavpanche...@gmail.comwrote: 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]

Re: Inheriting dictionary

2009-08-18 Thread Pavel Panchekha
On Aug 18, 4:23 pm, Jan Kaliszewski z...@chopin.edu.pl wrote: 18-08-2009 o 21:44:55 Pavel Panchekha pavpanche...@gmail.com 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 =

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
18-08-2009 o 22:27:41 Nat Williams nat.willi...@gmail.com wrote: On Tue, Aug 18, 2009 at 2:44 PM, Pavel Panchekha pavpanche...@gmail.comwrote: I want a dictionary that will transparently inherit from a parent dictionary. So, for example: a = InheritDict({1: one, 2: two, 4: four}) b =

Re: Inheriting dictionary

2009-08-18 Thread Pavel Panchekha
On Aug 18, 5:11 pm, Jan Kaliszewski z...@chopin.edu.pl wrote: 18-08-2009 o 22:27:41 Nat Williams nat.willi...@gmail.com wrote: On Tue, Aug 18, 2009 at 2:44 PM, Pavel Panchekha   pavpanche...@gmail.comwrote: I want a dictionary that will transparently inherit from a parent dictionary.

Re: Inheriting dictionary

2009-08-18 Thread Simon Forman
On Tue, Aug 18, 2009 at 6:08 PM, Simon Formansajmik...@gmail.com wrote: On Aug 18, 3:44 pm, Pavel Panchekha pavpanche...@gmail.com 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 =

Inheriting dictionary attributes and manipulate them in subclasses

2009-04-17 Thread Dominik Ruf
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() c2 = child2() print c1.dic {'1': '2', '2': '2'} print

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() c2 = child2() print c1.dic

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