Message126456
Hello!
Is it intentional, that the default argument is ALWAYS evaluated, even if it is not needed???
Is it not a bug, that this method has no short-circuit eval (http://en.wikipedia.org/wiki/Short-circuit_evaluation)
??
Example1:
=========
infinite = 1e100
one_div_by = {0.0 : infinite}
def func(n):
return one_div_by.setdefault(float(n), 1/float(n))
for i in [1, 2, 3, 4]:
print i, func(i)
print one_div_by
# works!!
for i in [0, 1, 2, 3, 4]: # added 0 -> FAIL!
print i, func(i)
print one_div_by
# fail!!
Example2:
=========
fib_d = {0 : 0, 1 : 1}
def fibonacci(n):
return fib_d.setdefault(n, fibonacci(n-1) + fibonacci(n-2))
for i in range(10):
print i, fibonacci(i)
print fib_d |
|
Date |
User |
Action |
Args |
2011-01-18 10:54:38 | albert.neu | set | recipients:
+ albert.neu |
2011-01-18 10:54:38 | albert.neu | set | messageid: <1295348078.83.0.563667045333.issue10930@psf.upfronthosting.co.za> |
2011-01-18 10:54:36 | albert.neu | link | issue10930 messages |
2011-01-18 10:54:35 | albert.neu | create | |
|