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()

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',