Yielding a chain of values

viridia at gmail.com viridia at gmail.com
Thu Sep 1 03:11:46 EDT 2005


This is why my original proposal used the '*' operator rather than a
keyword. The reasoning behind this is as follows: When calling a
function, a parameter of the form "*expression" expands to a list of
arguments. From the Python reference manual:

"If the syntax '*expression' appears in the function call, 'expression'
must evaluate to a sequence. Elements from this sequence are treated as
if they were additional positional arguments."

By (somewhat stretched) analogy, "yield *expression" would "expand" the
sequence into a series of multiple yields.

Of course, now that yield is an expression (as stated above), you would
indeed have to account for the fact that the yield statement used in
this way would yield a sequence of values:

   for x in yield *[ 1, 2, 3 ]:
      print x

So the '*' would not only signal that multiple values were being
yielded, but that multiple values are also being returned.

-- Talin




More information about the Python-list mailing list