PEP 255: Simple Generators

Neil Schemenauer nas at python.ca
Mon Jun 18 22:44:58 EDT 2001


Rainer Deyke wrote:
> 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
>   else:
>     return x # Or maybe not.

No and no.  The above code would raise a syntax error when
compiled.

  Neil




More information about the Python-list mailing list