Python 3.x 嵌套异步理解
以下工作很好:Python 3.x 嵌套异步理解,python-3.x,asynchronous,dictionary-comprehension,Python 3.x,Asynchronous,Dictionary Comprehension,以下工作很好: async def foo(n): await asyncio.sleep(0) return n async def bar(): return { n: await foo(n) for n in [1, 2, 3] } 但是嵌套版本失败,出现了SyntaxError:asynchronous comprehension(异步函数之外的异步理解): async def bar(): return {
async def foo(n):
await asyncio.sleep(0)
return n
async def bar():
return {
n: await foo(n) for n in [1, 2, 3]
}
但是嵌套版本失败,出现了SyntaxError:asynchronous comprehension(异步函数之外的异步理解)
:
async def bar():
return {
i: {
n: await foo(n) for n in [1, 2, 3]
} for i in [1,2,3]
}
它看起来像一只虫子,所以我是一个。它看起来像一只虫子,所以我是一个。