Default parameters
Bengt Richter
bokr at oz.net
Sat Dec 20 09:19:11 EST 2003
On Sat, 20 Dec 2003 06:56:07 GMT, Carl Banks <imbosol at aerojockey.invalid> wrote:
[...]
>I said a non-constant default argument wasn't useful. As evidence
>against, you suggest that the function is "consistent."
>
>Now, do have any evidence that non-constant, default arguments (as
>they are now) are USEFUL?
>From zenmeister Tim Peter's fixedpoint module (argue with that ;-):
def _tento(n, cache={}):
try:
return cache[n]
except KeyError:
answer = cache[n] = 10L ** n
return answer
That's useful, but IMO not the optimal syntax, because cache here is really not
being used as a parameter. That's why I would like a way to bind locals similarly
without being part of the calling signature. E.g.,
def _tento(n)(
# preset bindings evaluated here at def-time
cache={}
):
try:
return cache[n]
except KeyError:
answer = cache[n] = 10L ** n
return answer
Regards,
Bengt Richter
More information about the Python-list
mailing list