A default in the __init__ is like a class variable?

Just just at xs4all.nl
Sun Mar 30 16:12:35 CEST 2003


In article <35404b41.0303300501.27ae4054 at posting.google.com>,
 UNZRCHUYBTAS at spammotel.com (Jens Gelhaar) wrote:

> Is this a feature?
> 
> >>> class test:
> ...   def __init__(self,t=[]):
> ...       self.t=t
> ... 
> >>> t1=test(); t2=test()
> >>> t1.t.append("feature?")
> >>> print t1.t
> ['feature?']
> >>> print t2.t
> ['feature?']
> >>> 
> 
> I know why both t has the same list, but I would not expect this. Each
> instance should have it's own list.

Well, if you really did know why it's the same list, you _would_ expect 
this. It's a FAQ btw:

  http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.025.htp

Just




More information about the Python-list mailing list