Yielding a chain of values

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Wed Aug 31 13:23:03 CEST 2005

Matt Hammond wrote:
>> Well, maybe it's right both ways ;-) I.e., even though yield "is" now
>> an expression, it is valid to use it as an expression-statement which
>> evaluates the expression and discards the value. So I think you could
>> still use the currently illegal "yield in" token sequence to mean that
>> what follows is to be taken as an iterable whose full sequence is
>> to be yielded sequentially as if
>>     yield in iterable
>> were sugar for
>>     for _ in iterable: yield _
> "yield in" could make sense when thought of as an expression too.
>      x = yield in iterable
> Would behave like a list comprehension. x would be assigned a list  
> containing
> the results of the successive yields. Equivalent to:
> 	x = [ yield r for r in iterable ]

Which is quite different from

x = (yield) in iterable

which is currently (PEP 342) equivalent to

_ = (yield)
x = _ in iterable

So, no further tinkering with yield, I'm afraid.


More information about the Python-list mailing list