PEP 255: Simple Generators

Rainer Deyke root at
Mon Jun 18 22:25:19 EDT 2001

"Neil Schemenauer" <nas at> wrote in message
news:mailman.992912968.20037.python-list at
> 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?

def f(x):
  if x == 5:
    yield 5 # Look ma, I'm a generator.
    return x # Or maybe not.

Rainer Deyke (root at
Shareware computer games           - 
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

More information about the Python-list mailing list