<dict>.setdefault()
Erik Max Francis
max at alcyone.com
Thu Jul 31 13:23:21 EDT 2003
Tino Lange wrote:
> I just realized that <dict>.setdefault *always* executes the second
> argument - even if it's not necessary, because the requested item in
> the first argument exists.
>
> This is not what I expected - why evaluate the second argument if it's
> not needed? Also this can lead to side-effects!
Because Python doesn't have macros or special forms that look like
functions. If you see something that looks like a function, it
evaluates all arguments before it calls the function. Always. Changing
this would cause confusion, not resolve it.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ There's a reason why we / Keep chasing morning
\__/ Sandra St. Victor
More information about the Python-list
mailing list