Is this correct behavior for default parameters?
Fredrik Lundh
fredrik at pythonware.com
Wed Jul 16 03:31:30 EDT 2008
Bruce Pearson wrote:
> The first call to test has the file_list empty but on the second call to
> test the file_list is no longer empty but contains the values appended
> in the first call.
>
> Is this correct behavior? I'm using python 2.5
yes:
http://docs.python.org/ref/function.html
"Default parameter values are evaluated when the function
definition is executed." (in bold, even)
it's also explained in the tutorial (section 4.7.1) and in the FAQ.
(it's always a good idea to double-check the documentation or google a
little before convincing yourself that you may have found a bug in a
commonly used part of a system that's over 15 years old and has been
used by hundred of thousands of programmers).
</F>
More information about the Python-list
mailing list