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 dsblank
Recipients
Date 2004-10-29.00:59:42
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
I know that this has been broken for a long time, but I
thought that it would be addressed by 2.4. I couldn't
find it in the bug database. Here's the problem:

$ python2.4
Python 2.4b1 (#1, Oct 25 2004, 01:44:03)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> x = [lambda:a for a in range(5)]
>>> x[0]()
4
>>> x[1]()
4

The workaround is the old bind-the-arg trick:

>>> x = [lambda a=a:a for a in range(5)]
>>> x[0]()
0
>>> x[1]()
1
History
Date User Action Args
2007-08-23 14:27:09adminlinkissue1056483 messages
2007-08-23 14:27:09admincreate