classification
Title: strage default value behaviour
Type: Stage:
Components: None Versions: Python 2.4, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, dominik.holler
Priority: normal Keywords:

Created on 2008-09-24 15:17 by dominik.holler, last changed 2008-09-24 18:33 by dominik.holler. This issue is now closed.

Files
File name Uploaded Description Edit
test.py dominik.holler, 2008-09-24 15:17
index.html dominik.holler, 2008-09-24 15:17
Messages (3)
msg73718 - (view) Author: (dominik.holler) Date: 2008-09-24 15:17
The behaviour is changing, if I toogle comment lines 10 + 11.


Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
msg73723 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-24 15:58
Your script is subject to the "shared default value" syndrome, explained
here:
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects

As indicated in the FAQ, your function could be rewritten like this:

def getElementsByAttrib(self, value, AName="ID-REF", list=None):
  if list is None:
      list = []
  ...

to have a less surprising behavior.
msg73745 - (view) Author: (dominik.holler) Date: 2008-09-24 18:33
thx
sorry reporting this bug
History
Date User Action Args
2008-09-24 18:33:04dominik.hollersetmessages: + msg73745
2008-09-24 15:58:27amaury.forgeotdarcsetstatus: open -> closed
resolution: not a bug
messages: + msg73723
nosy: + amaury.forgeotdarc
2008-09-24 15:17:45dominik.hollersetfiles: + index.html
2008-09-24 15:17:22dominik.hollercreate