Re: initializing with empty list as default causes freaky problems

2009-07-28 Thread Luis Alberto Zarrabeitia Gomez
Quoting Reckoner : > Hi, > > Observe the following: > > In [202]: class Foo(): >.: def __init__(self,h=[]): >.: self.h=h [...] > In [207]: f.h.append(10) > > In [208]: f.h > Out[208]: [10] > > In [209]: g.h > Out[209]: [10] > > The question is: why is g.h updated

Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread Gary Herron
Reckoner wrote: Hi, Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h .: .: In [203]: f=Foo() In [204]: g=Foo() In [205]: g.h Out[205]: [] In [206]: f.h Out[206]: [] In [207]: f.h.append(10) In [208]: f.h Out[208]

Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread Benjamin Kaplan
On Mon, Jul 27, 2009 at 1:40 PM, Reckoner wrote: > Hi, > > Observe the following: > > In [202]: class Foo(): >   .:     def __init__(self,h=[]): >   .:         self.h=h >   .: >   .: > > In [203]: f=Foo() > > In [204]: g=Foo() > > In [205]: g.h > Out[205]: [] > > In [206]: f.h > Out

Re: initializing with empty list as default causes freaky problems

2009-07-27 Thread MRAB
Reckoner wrote: Hi, X-Antispam: NO; Spamcatcher 5.2.1. Score 50 Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h .: .: In [203]: f=Foo() In [204]: g=Foo() In [205]: g.h Out[205]: [] In [206]: f.h Out[206]: [] In [