where dos the default agument live in? local name spaces or gloabal namespaces or else?
Erik Max Francis
max at alcyone.com
Fri Aug 16 18:48:51 EDT 2002
Matt Gerrans wrote:
> > Side note: you probably don't want a mutable as a function default.
>
> Why is that?
Because usually when that appears in code it is not what is intended and
is often a bug; it's a FAQ of the kind of "This is behaving totally
strangely, I have no idea what's going on here" issues.
Usually a better pattern for otherwise-mutable defaults is something
like:
def f(l=None):
if l is None:
l = [] # this will make a new list each time
...
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
Church / http://www.alcyone.com/pyos/church/
A lambda calculus explorer in Python.
More information about the Python-list
mailing list