[Python-ideas] Using yield inside a comprehension.

Jonathan Slenders jonathan at slenders.be
Tue Nov 26 19:22:53 CET 2013


You can see an early side effect in "func" here, which could also trigger
exceptions early.


2013/11/26 Andrew Barnert <abarnert at yahoo.com>

> On Nov 26, 2013, at 7:33, Jonathan Slenders <jonathan at slenders.be> wrote:
>
> > What I tried to do, with my knowledge of Python 2 generators, is the
> following, but that doesn't work.
> >
> > @coroutine
> > def process(futures, func):
> >     return [ func((yield from f)) for f in futures ]
> >
> > They are also not equivalent. Using gather(), we have to wait before all
> the futures are ready, while in the second example, we could start creating
> the list on the fly. (Note that in this case "yield" instead of "yield
> from" would also work.)
>
> What would be the benefit of starting to create the list on the fly? You
> can't actually do anything with it, or even see it from any code, until
> it's completed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131126/40f99ddb/attachment.html>


More information about the Python-ideas mailing list