Fuzzyman wrote:
[...]
>
> Having default arguments evaluated when the function is defined is
> unintuitive and unpythonic.
With due respect that's a matter of opinion.
Having default arguments evaluated when the function is defined is the
result of several design decisions in Python, not the least of which is
the decision to have "def" be an executable statement. Ever wondered how
come you can def the same function name several times in the same
module? It's simply because on of def's side-effects is the binding of
its name in the current namespace.
Unfortunately there's absolutely no guarantee that the namespace context
when a function is called will bear any relation to the namespace
context when it was defined (particularly given that definition and call
can take place in entirely separate modules). So, how would one specify
a "deferred expression" to be evaluated when the function is called
rather than when it is defined? There presumably has to be some
technique that's different from the current ones, since presumably you
would also want to retain the option of having the default evaluated at
definition time.
I still haven't seen any reasonable suggestions as to how one might
exactly specify the execution context for such a deferred expression,
let alone how to spell the deferred expression itself. Would you have us
provide a code object that can be eval()'d?
regards
Steve
--
Steve Holden
http://www.holdenweb.com/
Python Web Programming
http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119