Mike Meyer wrote:
> Antoon Pardon <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>                        
> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to