On 2005-12-01, Mike Meyer <[EMAIL PROTECTED]> 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?

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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to