[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)
Ivan Levkivskyi levkivskyi at gmail.com
Thu Nov 23 07:42:59 EST 2017
- Previous message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Next message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 23 November 2017 at 13:30, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Thu, 23 Nov 2017 14:17:32 +0200 Serhiy Storchaka <storchaka at gmail.com> wrote: > > I used the "yield" statement, but I never used the "yield" expressions. > And I can't found examples. Could you please present a real-world use > case for the "yield" (not "yield from") expression?
Of course I can. "yield" expressions are important for writing Python 2-compatible asynchronous code while avoiding callback hell: See e.g. http://www.tornadoweb.org/en/stable/gen.html <https://mail.python.org/mailman/listinfo/python-dev>
Great, so I open this page and see this code:
results = [] for future in list_of_futures: results.append(yield future)
Interesting, why don't they use a comprehension for this and instead need
to invent a whole tornado.gen.multi
function?
-- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171123/1a81987c/attachment.html>
- Previous message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Next message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]