My (late) beef with Simple Generator syntax (PEP 255)
Just
just at xs4all.nl
Thu Nov 14 04:58:51 EST 2002
In article <mailman.1037219902.17042.python-list at python.org>,
Cameron Horn <camhorn at mac.com> wrote:
> If I want to write an empty class, I do this:
> class foo:
> pass
>
> If I want to write an empty function, I write this:
> def foo():
> pass
> -or-
> def foo():
> return
>
> 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
IMO the best idiom for this currently is
def foo():
while 0:
yield "whatever"
That's much better than the putting the yield after a return...
Just
More information about the Python-list
mailing list