Idan Sofer wrote: > > I have found a rather annoying bug in Python, present in both Python 1.5 > and Python 2.0. > > If a class has an argument with a default of an empty dictionary, then > all instances of the same class will point to the same dictionary, > unless the dictionary is explictly defined by the constructor. maybe you should check the documentation (or the FAQ) before submitting bugs? http://www.python.org/doc/current/ref/function.html Default parameter values are evaluated when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that that same ``pre- computed'' value is used for each call. This is especially important to understand when a default parameter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified. Cheers /F PS. when you do report real bugs, please use the bug tracker: http://sourceforge.net/tracker/?group_id=5470&atid=105470 "is this a bug" questions should be sent to comp.lang.python
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4