Re: constructor list slice confusion

2005-07-14 Thread Peter Otten
Simon Morgan wrote: Can somebody please explain to me why: class SomeClass: def __init__(self, contents=[]): self.contents = contents[:] def add(self, element): self.contents.append(element) when called a second time (i.e. to create a new instance of a SomeClass

Re: constructor list slice confusion

2005-07-14 Thread Simon Morgan
On Thu, 14 Jul 2005 08:38:36 +0200, Peter Otten wrote: Maybe, after a little renaming you can see it yourself: class SomeClass: def __init__(self, default_contents=[]): # make a copy of default_contents that is # kept in a SomeClass instance self.contents =

constructor list slice confusion

2005-07-13 Thread Simon Morgan
Hi, Can somebody please explain to me why: class SomeClass: def __init__(self, contents=[]): self.contents = contents[:] def add(self, element): self.contents.append(element) when called a second time (i.e. to create a new instance of a SomeClass object) results in