PEP 255: Simple Generators
root at rainerdeyke.com
Tue Jun 19 04:25:19 CEST 2001
"Neil Schemenauer" <nas at python.ca> wrote in message
news:mailman.992912968.20037.python-list at python.org...
> Not really. For example, the functions
> def f1(n):
> for i in range(n):
> yeild i
> def f2(n):
> return iter(range(n))
> do pretty much the same thing. "yeild" is just a handy way of
> creating iterators.
In other words, whether a function is a generator or not is determined at
run-time. The following would work, right?
if x == 5:
yield 5 # Look ma, I'm a generator.
return x # Or maybe not.
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list