My (late) beef with Simple Generator syntax (PEP 255)

Alan Kennedy alanmk at hotmail.com
Wed Nov 13 16:32:53 EST 2002


Cameron Horn wrote:

> If I want to write an empty generator, I write this(?):
> def foo():
>   return
>   yield "never"

> Assuming that having an empty generator is as valid as empty functions
> and classes, what kind of linguistic cruft is that?  I expect better
> out of python, dang it.
> 
> What I'd like to write is:
> gen foo():
>    return

What is the semantic of "an empty generator", i.e. what does it mean? A
generator that never generates any values?

Would this fulfill your requirement? (And not upset you so much :-)

def nullgen():
    raise StopIteration
    yield "never called"

>>> for x in nullgen():
...     print x
...
>>>
>>>

It doesn't bother me.

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan



More information about the Python-list mailing list