Problem with generator expression and class definition

Discussion in 'Python' started by Maric Michaud, Dec 7, 2007.

  1. 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.
     
    Maric Michaud, Dec 7, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jianli Shen
    Replies:
    1
    Views:
    642
    Victor Bazarov
    Mar 13, 2005
  2. snacktime
    Replies:
    13
    Views:
    586
    Dan Sommers
    Feb 22, 2005
  3. Replies:
    9
    Views:
    607
  4. Ark
    Replies:
    1
    Views:
    451
    Chris Torek
    Aug 7, 2004
  5. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Decralation of class inside other class and definition outside this class

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 13, 2007, in forum: C++
    Replies:
    2
    Views:
    354
    Alf P. Steinbach
    Jul 13, 2007
Loading...

Share This Page