yield keyword reserved

holger krekel pyth at devel.trillke.net
Sun Sep 1 18:11:55 CEST 2002


Erik Price wrote:
> I'm sorry if this is an easily answered-question.  I have Python2.2 
> running on my system (it is installed on Darwin by default in Mac OS X 
> 10.2), and am learning about iterators from 
> <http://python.org/doc/current/whatsnew/node5.html>, but the keyword 
> doesn't appear to be present on my system:
> 
> Python 2.2 (#1, 07/14/02, 23:25:09)
> [GCC Apple cpp-precomp 6.14] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> def generate_ints(N):
> ...  for i in range(N):
> ...   yield i
> <string>:3: Warning: 'yield' will become a reserved keyword in the 
> future
>    File "<string>", line 3
>      yield i
>            ^
> SyntaxError: invalid syntax
>  >>>

With python2.2 you have to explicitely enable generators.  put a 

    from __future__ import generators

at the beginning of a script or in an interactive session.

With the future python2.3 you don't need this.

    holger




More information about the Python-list mailing list