Ezio Melotti added the comment:

I'm having some problem at deciding what the title of the FAQ should be, and 
what the actual problem is.  ISTM that OP's problem is the same as:
>>> x = 1
>>> def foo(): return x
... 
>>> x = 2
>>> foo()
2

except that he has 3 lambdas in a loop that get attached to an instance rather 
than a simple function -- but the problem is that in both cases the function 
references a global variable whose value is retrieved at calling time rather 
that being set at definition time.
IOW the solution should be clear, but the code is complex enough that it's not 
easy to recognize the analogy with the simpler case.
I'm not even sure this has anything to do with closures, unless you consider 
the global scope a closure.

Maybe the "What are the rules for local and global variables in Python?" FAQ 
could be expanded with a few examples to cover this case too.

----------
assignee: ezio.melotti -> 
nosy: +chris.jerdonek

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13094>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to