bug or feature?
Ben Sizer
kylotan at gmail.com
Wed Oct 5 08:31:22 EDT 2005
Fredrik Lundh wrote:
> it's also mentioned in chapter 4 of the tutorial:
>
> http://docs.python.org/tut/node6.html#SECTION006710000000000000000
>
> "*Important warning*: The default value is evaluated only once. This
> makes a difference when the default is a mutable object such as a list,
> dictionary, or instances of most classes. "
Perhaps it would be a good idea if Python actually raised a warning
(SyntaxWarning?) if you use an unnamed list or dict as a default
argument. This would doubtless help quite a few beginners. And for
people who really do want that behaviour, working around the warning
should involve minimal extra code, with extra clarity thrown in for
free.
--
Ben Sizer
More information about the Python-list
mailing list