Ezio Melotti <ezio.melo...@gmail.com> added the comment:

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).

----------
assignee: docs@python -> 
components: +None -Documentation
nosy: +ezio.melotti
stage: needs patch -> 
type: behavior -> 
versions:  -Python 3.2, Python 3.3

_______________________________________
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