PEP 255: Simple Generators, Revised Posting
bh at intevation.de
Mon Jun 25 04:57:25 EDT 2001
Neil Schemenauer <nas at python.ca> writes:
> Bernhard Herzog wrote:
> > It seems to me that as it stands, empty generators are a bit too
> > difficult to write, so I think we need an easier way to write them. One
> > way to write them would be
> > def g():
> > yield
> What is wrong with:
> def g():
> return 
If I have another function f that expects g to return an iterator this
> If you really want an iterator object you can do:
> def g():
> return iter()
Although this would, of course.
> I don't know why anyone would care though.
The only reason would be consistency, I guess, which in practice is not
> > If generators weren't created with a def statement it would be a bit
> > more obvious:
> > generator g():
> > pass
> I don't think Guido will be convinced that we need a new keyword just
> because it makes it easy to write silly code.
I wouldn't say it's silly. Just as a normal function that does nothing
is not silly either.
With regard to the generator keyword, I actually think that using def
for generators is correct, because even if the function contains yield,
the object created by the def statement is a function object. An of
course, a generator is pretty similar to a function.
Intevation GmbH http://intevation.de/
More information about the Python-list