late-binding

print() inside thread outputs wrong value

print() inside thread outputs wrong value Question: I’m trying to recreate a stupid idea called sleep sort, however the output is far from expected. I am expecting 0 1 2 3 5 However I get 0 5 5 5 5 …which is wierd because the thread does: sleep for (item) seconds and then print that …

Total answers: 1

How do lexical closures work?

How do lexical closures work? Question: While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python: flist = [] for i in xrange(3): def func(x): return x * i flist.append(func) for f in flist: print f(2) Note that this example mindfully avoids lambda. It …

Total answers: 10