Unexpected Python Behavior
Fredrik Lundh
fredrik at pythonware.com
Fri Sep 24 04:47:18 EDT 2004
Simon Wittber wrote:
> It took me a while to work out that default keyword argument values
> are likely only evaluated once, which caused the empty dict to be
> shared across classes...
some relevant links:
http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects
http://docs.python.org/tut/node6.html#SECTION006710000000000000000
http://docs.python.org/ref/function.html
> It certainly something newbie python coders should look out for!
it's a well-known "you'll only do this once" mistake. which is a good thing,
because when you understand why this happens, you have learned a lot about
how "def" and objects work in Python...
</F>
More information about the Python-list
mailing list