Death to tuples!
Fuzzyman
fuzzyman at gmail.com
Thu Dec 1 11:56:38 EST 2005
Mike Meyer wrote:
> Antoon Pardon <apardon at forel.vub.ac.be> writes:
> > I know what happens, I would like to know, why they made this choice.
> > One could argue that the expression for the default argument belongs
> > to the code for the function and thus should be executed at call time.
> > Not at definion time. Just as other expressions in the function are
> > not evaluated at definition time.
>
> The idiom to get a default argument evaluated at call time with the
> current behavior is:
>
> def f(arg = None):
> if arg is None:
> arg = BuildArg()
>
> What's the idiom to get a default argument evaluated at definition
> time if it were as you suggested?
>
Having default arguments evaluated at definition time certainly bites a
lot of newbies. It allows useful tricks with nested scopes though.
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
> <mike
> --
> Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list