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

Neil Schemenauer nas at python.ca
Thu Nov 14 16:36:48 EST 2002


Just wrote:
> IMO the best idiom for this currently is
> 
>   def foo():
>       while 0:
>           yield "whatever"

This whole discussion is silly, IMHO.  The best idiom is:

    def foo():
        return []

If you really want an interator, then:

    def foo():
        return iter([])

Requiring that the type returned by foo be <type 'generator'> is
un-Pythonic and silly.  If you do want that, the best solution would be
the very clever suggestion of:

    def foo()
        if 0: yield None

  Neil




More information about the Python-list mailing list