A default in the __init__ is like a class variable?

Jens Gelhaar UNZRCHUYBTAS at spammotel.com
Sun Mar 30 15:01:09 CEST 2003


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.




More information about the Python-list mailing list