This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Problem with dictionary default argument
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: tim.peters
Priority: normal Keywords:

Created on 2001-04-18 05:29 by anonymous, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (2)
msg4338 - (view) Author: Nobody/Anonymous (nobody) Date: 2001-04-18 05:29
-- Python 2.0 Win32 --

It seems to be that _default argument values_ can be 
changed permanently if they are dictionaries.

Code sample:

def f(a = 1):
  print a
  a = 2

>>>f()
1
>>>f()
1

--> ok

def g(mydic = {}):
  print mydic
  mydic["test"] = 1

>>>g()
{}
>>>g()
{'test': 1}

--> bad (default argument value for 'mydic' changed)
msg4339 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-04-18 09:08
Logged In: YES 
user_id=31435

Not a bug.  Please see the Python FAQ entry 6.25, "Why are 
default values sometimes shared between objects?"

http://www.python.org/cgi-bin/faqw.py?
req=show&file=faq06.025.htp
History
Date User Action Args
2022-04-10 16:03:58adminsetgithub: 34361
2001-04-18 05:29:22anonymouscreate