Death to tuples!
Antoon Pardon
apardon at forel.vub.ac.be
Thu Dec 1 14:39:42 EST 2005
On 2005-12-01, Mike Meyer <mwm at mired.org> 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?
Well there are two possibilities I can think of:
1)
arg_default = ...
def f(arg = arg_default):
...
2)
def f(arg = None):
if arg is None:
arg = default.
--
Antoon Pardon
More information about the Python-list
mailing list