This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients Tomáš.Dvořák, chris.jerdonek, docs@python, eric.araujo, ezio.melotti, r.david.murray
Date 2013-01-03.07:05:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1357196729.51.0.784233521419.issue13094@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-01-03 07:05:29ezio.melottisetrecipients: + ezio.melotti, eric.araujo, r.david.murray, chris.jerdonek, docs@python, Tomáš.Dvořák
2013-01-03 07:05:29ezio.melottisetmessageid: <1357196729.51.0.784233521419.issue13094@psf.upfronthosting.co.za>
2013-01-03 07:05:29ezio.melottilinkissue13094 messages
2013-01-03 07:05:28ezio.melotticreate