A
Alphones
Hi all,
def getFunc(x):
return lambda y : x + y
if __name__ == '__main__':
todo = []
proc = getFunc(1)
todo.append(lambda: proc(1))
proc = getFunc(2)
todo.append(lambda: proc(1))
proc = getFunc(3)
todo.append(lambda: proc(1))
todo.append(lambda: getFunc(1)(1))
todo.append(lambda: getFunc(2)(1))
todo.append(lambda: getFunc(3)(1))
for task in todo:
print task()
-----------
the program outputs:
4
4
4
2
3
4
in Python 2.6.
is that excpected?
def getFunc(x):
return lambda y : x + y
if __name__ == '__main__':
todo = []
proc = getFunc(1)
todo.append(lambda: proc(1))
proc = getFunc(2)
todo.append(lambda: proc(1))
proc = getFunc(3)
todo.append(lambda: proc(1))
todo.append(lambda: getFunc(1)(1))
todo.append(lambda: getFunc(2)(1))
todo.append(lambda: getFunc(3)(1))
for task in todo:
print task()
-----------
the program outputs:
4
4
4
2
3
4
in Python 2.6.
is that excpected?