PEP 255: Simple Generators, Revised Posting

Neil Schemenauer nas at python.ca
Sun Jun 24 19:18:27 EDT 2001


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 you really want an iterator object you can do:

    def g():
        return iter([])

I don't know why anyone would care though.

> 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.

  Neil




More information about the Python-list mailing list