(why) inconsistent yield/return syntax?

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Tue Feb 11 05:02:25 CET 2003


In article <mailman.1044911613.5107.python-list at python.org>, Mark
McEahern wrote:
>[Gerrit Holl]
>> An empty return is ok and return None, but an empty yield isn't.
>> My question is why...
>
>I'm curious whether you can state your question in terms of a goal that you
>are trying to accomplish.

How about avoiding the somewhat superfluous None at the end of
"yield None"? One may argue over whether this should or should not be
so, but it seems to be mostly a matter of taste (i.e. "it is more
convenient/consistent to allow an empty yield" vs. "it is prudent to
be explicit here, as one would usually want to yield something other
than None").

And, yes, there are certainly uses for generators that don't return
anything. (As you said (I think), Google is your friend ;)

-- 
Magnus Lie Hetland               "Nothing shocks me. I'm a scientist." 
http://hetland.org                                   -- Indiana Jones




More information about the Python-list mailing list