[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)
David Mertz mertz at gnosis.cx
Sat Nov 25 19:20:34 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 Sat, Nov 25, 2017 at 3:37 PM, Guido van Rossum <guido at python.org> wrote:
Maybe you didn't realize async/await don't need an event loop? Driving an async/await-based coroutine is just as simple as driving a yield-from-based one (
await
does exactly the same thing asyield from
).
I realize I can, but it seems far from straightforward. I guess this is really a python-list question or something, but what is the async/await spelling of something toy like:
In [1]: def fib(): ...: a, b = 1, 1 ...: while True: ...: yield a ...: a, b = b, a+b ...:
In [2]: from itertools import takewhile
In [3]: list(takewhile(lambda x: x<200, fib())) Out[3]: [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
Maybe the rest of the discussion should be about deprecation vs. SyntaxError in Python 3.7.
I vote SyntaxError, of course. :-)
-- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171125/0b1e900e/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 ]