can't import generators

Aahz aahz at
Sat Jun 29 22:59:27 CEST 2002

In article <Xns923CE7C804E6Fcliechtigmxnet at>,
Chris Liechti  <cliechti at> wrote:
>aahz at (Aahz) wrote in news:afl5je$4iu$1 at
>> In article <m2hejlc060.fsf at mother.paradise.lost>,
>> John Hunter  <jdhunter at> wrote:
>>>I am having trouble working with generators.  Anyone know what might
>>>cause this behavior:
>>>Python 2.2.1 (#1, Apr 22 2002, 21:20:54) [GCC 3.0.4] on linux2
>>>Type "help", "copyright", "credits" or "license" for more information.
>>>>>> from __future__ import generators
>>>Traceback (most recent call last):
>>>  File "<stdin>", line 1, in ?
>>>ImportError: cannot import name generators
>> Can't do this in interactive mode.  Use a script.
>?!?!? since when?
>$ python
>Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
>Type "help", "copyright", "credits" or "license" for more information.
>>>> from __future__ import generators
>>>> def g(x):
>...     for p in x: yield p
>>>> [x for x in g(range(3))]
>[0, 1, 2]

Huh.  That'll teach me to trust the combination of screen output and my
memory.  Here's some more weird stuff.  In a script, this works:

    from __future__ import generators

this fails with SyntaxError:

    print x
    from __future__ import generators

but it works in interactive mode:

    >>> x=1
    >>> print x
    >>> from __future__ import generators

Of course, none of this explains why John gets an ImportError, unless
he's got a completely screwed up installation.
Aahz (aahz at           <*>

Project Vote Smart:

More information about the Python-list mailing list