Johan a écrit :
Dear all,

Considering this test program:

def tst(a={}):

Stop here, we already know what will follow !-)

And yes, it's one of Python's most (in)famous gotchas : default arguments values are computed only once, at function definition time (that is, when the def statement is executed).

The correct way to write a function with mutable default arguments is:

def func(arg=None):
   if arg is None:
       arg = []
   # then proceed

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

Reply via email to