Unexpected Python Behavior

David Pokorny davebrok at soda.csua.berkeley.edu
Fri Sep 24 09:31:19 EDT 2004


"Fredrik Lundh" <fredrik at pythonware.com> wrote in message >
> it's a well-known "you'll only do this once" mistake.  which is a good
thing,

"Because of this feature, it is good programming practice to not use mutable
objects as default values." -- 
http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

Has it been discussed whether it would be a good idea to issue a warning in
this case? It strikes me that a warning wouldn't bother veteran programmers,
since it is really easy to avoid using a mutable default value (nearly
trivial to modify code that does use mutable default values). I'd imagine it
makes code more readable too.

David Pokorny





More information about the Python-list mailing list