yield from 有什么最佳的使用场景吗?

2017-07-31 16:41:45 +08:00
 rogwan
yield from iterable means for item in iterable: yield item
2069 次点击
所在节点    Python
8 条回复
est
2017-07-31 16:47:54 +08:00
chain iterable
lxml
2017-07-31 16:55:08 +08:00
yield from 个人用的不多,但他的近亲 await 则很常用。
CryMeatel
2017-07-31 19:03:10 +08:00
asyncio 模块常用
slideclick
2017-08-01 10:34:12 +08:00
describe your question in English then search it via Google you will get best answer.
NoAnyLove
2017-08-01 11:43:28 +08:00
4 楼正解
brucedone
2017-08-01 12:00:53 +08:00
转移控制权给子生成器,简单来说是打开一个双向通首,把最外层的调用方和最内层的子生器连接起来,这样二者就可以直接发送和产出值,使用 yield from 的块可以称为委派生成器
junnplus
2017-08-01 12:47:20 +08:00
@brucedone 这段话好熟悉😂。。。
brucedone
2017-08-01 14:20:46 +08:00
@junnplus 《流畅的 python 》,好书啊,例子也写的够详细

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/379301

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX