Bart Ogryczak a écrit :
> On 2008-01-18, citizen Zbigniew Braniecki testified:
(snip usual default mutable list arg problem)
>> class A():
>>
>>    def add (self, el):
>>      self.lst.extend(el)
>>
>>    def __init__ (self, val=[]):
>>      print val
>>      self.lst = val
> 
> What you want probably is:
>       def __init__ (self, val=None):
>               if(val == None):

Better to use an identity test here - there's only one instance of the 
None object, and identity test is faster than equality test (one 
function call faster IIRC !-). Also, the parens are totallu useless.

                 if val is None:

>                       self.lst = []
>               else:
>                       from copy import copy
>                       ### see also deepcopy
>                       self.lst = copy(val)

What makes you think the OP wants a copy ?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to