本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
yield from本质:
for item in iterable: yield item的缩写版
代码示例:
def g(x): yield from range(x , 0, -1) yield from range(x) print(list(g(5)))
利用yield from语句向生成器(协程)传送数据:
def writer(): while True: w = (yield) print('>>', w) def writer_wrapper(coro1): coro1.send(None) while True: try: x = (yield) coro1.send(x) except StopIteration: pass def writer_wrapper(coro2): yield from coro2
Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务