Bug in python!? persistent value of an optional parameter in function!
C Barr Leigh
cpblPublic at gmail.com
Wed Mar 7 21:39:21 EST 2007
Help! Have I found a serious bug?
This seems like highly undesired behaviour to me. From the program
below, I get output:
call1: ['sdf']
call2: ['Set within test for call2']
call3: ['Set within test for call2']
instead of what I should get,
call1: ['sdf']
call2: ['Set within test for call2']
call3: ['Set within test for call3']
I'm using Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02). The code is
below.
#!/usr/bin/python
def testPersistence(anarg,twooption=[]):
#print anarg
if not twooption:
twooption.append('Set within test for '+anarg)
print anarg +': '+str(twooption)
testPersistence('call1',twooption=['sdf']);
testPersistence('call2');
testPersistence('call3');
More information about the Python-list
mailing list