Yielding a chain of values

Kay Schluehr kay.schluehr at gmx.net
Wed Aug 31 14:59:38 EDT 2005


Reinhold Birkenfeld wrote:
> Kay Schluehr wrote:
> > Reinhold Birkenfeld wrote:
> >
> >> > 	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.
> >>
> >> Reinhold
> >
> > Is the statement
> >
> >    yield from iterable
> >
> > also in danger to be ambigous?
> >
> > The resolution of "(yield) from iterable" into
> >
> >  _ = (yield)
> >  x = _ from iterable
> >
> > would not result in valid Python syntax.
>
> Right.
>
> Problem is, how would you define the "from" syntax: Is its use as
> an expression allowed? What value does it have, then?
>
> Reinhold

Do you mention statements like this?

   x = (yield from [1,2,3])

I do think that such "yield-comprehensions" may be valid and raise a
StopIteration exception after being called three times by means of
next() or send(). 

Kay




More information about the Python-list mailing list