Hi,
given the following example class
class Test:
def f(self,a, L=[]):
L.append(a)
return L
and the following statements
a = Test()
a.f(0)
a.f(0)
a.f(0)
b = Test()
b.f(0)
this is the output I would like to have (i.e., expect)
>>> a = Test()
>>> a.f(0)
[0]
>>> a.f(0)
[0, 0]
>>> a.f(0)
[0, 0, 0]
>>> b = Test()
>>> b.f(0)
[0]
But this is what I get:
>>> a = Test()
>>> a.f(0)
[0]
>>> a.f(0)
[0, 0]
>>> a.f(0)
[0, 0, 0]
>>> b = Test()
>>> b.f(0)
[0, 0, 0, 0]
as you can see, the b.f method shares L with a.f.
How can I avoid this without using eg. self.L in an __init__?
Thanks in advance,
Karel.
--
http://mail.python.org/mailman/listinfo/python-list