can't import generators

Aahz aahz at pythoncraft.com
Sat Jun 29 16:59:27 EDT 2002


In article <Xns923CE7C804E6Fcliechtigmxnet at 62.2.16.82>,
Chris Liechti  <cliechti at gmx.net> wrote:
>aahz at pythoncraft.com (Aahz) wrote in news:afl5je$4iu$1 at panix1.panix.com:
>> In article <m2hejlc060.fsf at mother.paradise.lost>,
>> John Hunter  <jdhunter at nitace.bsd.uchicago.edu> 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:

    x=1
    from __future__ import generators

this fails with SyntaxError:

    x=1
    print x
    from __future__ import generators

but it works in interactive mode:

    >>> x=1
    >>> print x
    1
    >>> 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 pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/



More information about the Python-list mailing list