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 Tomáš.Dvořák
Recipients Tomáš.Dvořák
Date 2011-10-03.14:39:56
SpamBayes Score 1.6325137e-06
Marked as misclassified No
Message-id <1317652797.3.0.357677492942.issue13094@psf.upfronthosting.co.za>
In-reply-to
Content
I have this python script, and run it in python 2.7.2 (installed from EPD_free 7.1-2 (32-bit), but I guess this has nothing to do with EPD.
----8<---fail.py------

class X(object):
    pass

x = X()
items = ["foo", "bar", "baz"]

for each in items:
    setattr(x, each, lambda: each)
    
print("foo", x.foo())    
print("bar", x.bar())
print("baz", x.baz())

----8<---fail.py------

I'd naively expect it to print 
('foo', 'foo')
('bar', 'bar')
('baz', 'baz')

,but it surprisingly (and annoyingly) outputs
('foo', 'baz')
('bar', 'baz')
('baz', 'baz')

Please, tell me that this is a bug :) I'd hate it if this was the intended behaviour. I spent two hours today before I found out this was the cause of my program to fail.

Best regards,
  Tomáš Dvořák
History
Date User Action Args
2011-10-03 14:39:57Tomáš.Dvořáksetrecipients: + Tomáš.Dvořák
2011-10-03 14:39:57Tomáš.Dvořáksetmessageid: <1317652797.3.0.357677492942.issue13094@psf.upfronthosting.co.za>
2011-10-03 14:39:56Tomáš.Dvořáklinkissue13094 messages
2011-10-03 14:39:56Tomáš.Dvořákcreate