Generators: section 9.10 of the python tutorial

Paul Rubin http
Thu May 13 15:35:34 EDT 2004


"David Stockwell" <winexpert at hotmail.com> writes:
> Section 9.10 of the tutorial discusses the yield keyword.   When I
> tried using it I get the following SyntaxError.
> 
> What does this error mean?  Does it mean we can't use yield in our
> code?  

It means you're using an older version of Python in which yield isn't
a standard built-in keyword.  Try putting

    from __future__ import generators

at the very top of your source file to enable the yield statement.
The special import is there so that old code that uses "yield" as
(say) a variable name won't suddenly break.



More information about the Python-list mailing list