Ezio Melotti added the comment:
Attached a new patch.
--
Added file: http://bugs.python.org/file28563/issue13094-2.diff
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
___
R. David Murray added the comment:
Looks good to me.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
___
___
Python-bugs-list mailing list
Roundup Robot added the comment:
New changeset fdc894d44d82 by Ezio Melotti in branch '2.7':
#13094: add Programming FAQ entry about the behavior of closures.
http://hg.python.org/cpython/rev/fdc894d44d82
New changeset 02933454b7ce by Ezio Melotti in branch '3.2':
#13094: add Programming FAQ
Ezio Melotti added the comment:
Fixed, thanks for the review!
--
resolution: - fixed
stage: patch review - committed/rejected
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
R. David Murray added the comment:
The FAQ (as in, this question gets asked again and again) is something like
why do the lambdas I define in a loop all return the same result when the
input value was different when each one was defined?
The same applies to regular functions, but people
Ezio Melotti added the comment:
why do the lambdas I define in a loop all return the same result when
the input value was different when each one was defined?
I thought about that, but that sounds a bit too long/specific. It also has the
problem that the issue is not strictly related to
R. David Murray added the comment:
The point is, it is a FAQ. We are talking about updating the FAQ document. It
doesn't matter if the text is too specific, if it is in fact a FAQ. And it
is.
--
___
Python tracker rep...@bugs.python.org
Ezio Melotti added the comment:
Here's a patch.
--
keywords: +patch
stage: needs patch - patch review
Added file: http://bugs.python.org/file28550/issue13094.diff
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
Changes by Ezio Melotti ezio.melo...@gmail.com:
--
assignee: - ezio.melotti
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
___
___
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
Changes by Ezio Melotti ezio.melo...@gmail.com:
--
assignee: docs@python - ezio.melotti
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
___
Changes by Ezio Melotti ezio.melo...@gmail.com:
--
keywords: +easy
stage: - needs patch
type: - enhancement
versions: +Python 3.4
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
___
Changes by Éric Araujo mer...@netwok.org:
--
assignee: - docs@python
components: +Documentation -None
nosy: +eric.araujo
versions: +Python 3.2, Python 3.3
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13094
Changes by R. David Murray rdmur...@bitdance.com:
--
title: setattr misbehaves when used with lambdas inside for loop - Need
Programming FAQ entry for the behavior of closures
___
Python tracker rep...@bugs.python.org
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'
Tomáš Dvořák dvto...@gmail.com added the comment:
Thank you all very much for the super-quick responses. I'm used to smalltalk,
so the python variable binding behaviour is unnatural to me, but I guess there
must have been some reasons for making it behave this way.
Ezio, the
lambda
Ezio Melotti ezio.melo...@gmail.com added the comment:
Maybe with a different name is less confusing: lambda return_value=each:
return_value
This copies the value of 'each' in a variable called 'return_value' that is
local to the lambda. Since the copy happens when the lambdas are defined,
17 matches
Mail list logo