PEP 255: Simple Generators
Zen
zen at shangri-la.dropbear.id.au
Tue Jun 19 20:38:36 EDT 2001
"Russell E. Owen" <owen at astrono.junkwashington.emu> writes:
>Several proposals come to mind. They are all compatible with each other:
>1) Have users explicitly say "raise StopIter" when they mean it. This is
>2) Add a keyword, such as "stop". It could always raise StopIter, or
>3) Have "return" mean exactly what it means now, but also have a
4) Have 'yield' with no arguments raise a StopIter.
Having 'yield' and 'return' in the same function could then become
a syntax error.
Alternativly, it could be used to save a few lines
for things-that-generate-infinitly.
def mygen():
for i in range(1,10):
yield i
return 10
may be identical to
def mygen():
while 1:
for i in range(1,11):
yield i
This would also makes the following a valid generator:
def void():
return None
More information about the Python-list
mailing list