Yes, they do have that limitation. I don't see it written out explicitly, though, either in the PEP about generators
http://www.python.org/peps/pep-0255.html
or in Andrew Kuchling's less formal description from his "What's new in Python 2.2" document:
http://www.amk.ca/python/2.2/index.html
The restriction is implied in both docs, though:
The latter doc includes:
Any function containing a yield statement is a generator function; this is detected by Python's bytecode compiler which compiles the function specially as a result.
and the former one includes:
The yield statement may only be used inside functions. A function that contains a yield statement is called a generator function.
|