PEP 255: Simple Generators

Gordon McMillan gmcm at hypernet.com
Wed Jun 20 09:09:11 EDT 2001


Greg Ewing wrote:

>But under PEP 255, there is *nothing* anywhere
>in the code that you can point to and say "look,
>here is where the generator-iterator is created!"

Sure there is. It's in the "for".

Before iterators, you could look at 

 for x in f():

and say "Aha, f() returns a sequence". 

In 2.2, you'll have to say "f() returns something
that follows the iterator protocol".

Now if a casual reader happens upon the definition
of f, misses the "yield" and comes away with the
impression that f is an "ordinary" function, I say
"So what?". Monte Carlo sampling is no way to 
understand code.

- Gordon



More information about the Python-list mailing list