Default parameters
Terry Reedy
tjreedy at udel.edu
Sun Dec 21 12:02:04 EST 2003
"Bengt Richter" <bokr at oz.net> wrote in message
news:bs1lov$3vu$0 at 216.39.172.122...
> 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
I have also thought of using a ';' as in
def _tento(n; cache = {}):
[etc]
to indicate a def-time initialized non-parameter.
Terry J. Reedy
More information about the Python-list
mailing list