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, docs@python, ezio.melotti, r.david.murray
Date 2011-10-03.15:03:18
SpamBayes Score 1.6290738e-05
Marked as misclassified No
Message-id <1317654199.49.0.0212202123252.issue13094@psf.upfronthosting.co.za>
In-reply-to
Content
To understand better what's going on, try to change the value of 'each' after the 3 prints and then call again the 3 methods: you will see that they now return the new value of each.  This is because the lambdas refer to global 'each' (that at the end of the loop is set to 'baz').
If you do setattr(x, each, lambda each=each: each), the each will be local to the lambda, and it will then work as expected.

An entry in the FAQ would be useful, I thought it was there already but apparently it's not (I'm pretty sure I saw this already somewhere in the doc, but I can't seem to find where).
History
Date User Action Args
2011-10-03 15:03:19ezio.melottisetrecipients: + ezio.melotti, r.david.murray, docs@python, Tomáš.Dvořák
2011-10-03 15:03:19ezio.melottisetmessageid: <1317654199.49.0.0212202123252.issue13094@psf.upfronthosting.co.za>
2011-10-03 15:03:18ezio.melottilinkissue13094 messages
2011-10-03 15:03:18ezio.melotticreate