Problem with generator expression and class definition
Maric Michaud
maric at aristote.info
Fri Dec 7 11:40:33 EST 2007
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.
More information about the Python-list
mailing list