471,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Problem with generator expression and class definition

I faced a strange behavior with generator expression, which seems like a bug, for both
python 2.4 and 2.5 :
>>class A :
.... a = 1, 2, 3
.... b = 1, 2, 3
.... C = list((e,f) for e in a for f in b)
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in A
File "<stdin>", line 4, in <genexpr>
NameError: global name 'b' is not defined
>>class A :
.... a = 1, 2, 3
.... b = 1, 2, 3
.... C = [ (e,f) for e in a for f in b ]
....
>>A.C
[(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)]

Any comment ? I'm ready to report it as a bug if there is no objection.
Dec 7 '07 #1
0 939

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

72 posts views Thread by Raymond Hettinger | last post: by
45 posts views Thread by Joh | last post: by
3 posts views Thread by andy.leszczynski | last post: by
13 posts views Thread by John Doe | last post: by
14 posts views Thread by castironpi | last post: by
8 posts views Thread by Rahul | last post: by
6 posts views Thread by wij | last post: by
8 posts views Thread by Stefano Sabatini | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.