PEP 255: Simple Generators
paulp at ActiveState.com
Wed Jun 20 17:26:12 EDT 2001
David Bolen wrote:
> "Russell E. Owen" <owen at astrono.junkwashington.emu> writes:
> > Since a generator is very different than a function, why not mark it as
> > such right up front?
> > I agree that revealing the internal implementation is bad. I disagree
> > that return is reasonable, though it is much less of a concern if a
> > generator doesn't look like a function right up front.
> But isn't a generator really just a function that is returning an
> iterator? That is, why is it "very" different from a function,
> internal implementation aside, which we agree it's not necessary to
Those who think that generators should have a special declaration syntax
are not worried about how the generator looks to the caller. They are
worried about people stumbling upon the generator feature of Python
without understanding that a single keyword in the middle of a function
can totally change the interpretation of that function. It changes what
happens when the function is first called, what the function can return,
when it can return it, and what can happen in the middle of its
execution (i.e. arbitrary code elsewhere in the program could be
We think that such a radical change in semantics for the code block
should be labelled with something stronger than a buried keyword. And we
are discussing this on the python-iterators list.
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook
More information about the Python-list