python yield的用法
next方法
#coding=utf-8 from time import sleep def test(l1): for l in l1: print l sleep(5) yield 'result:%s' % l l1=[1,2,3,4,5] t=test(l1=l1) for l in l1: print t.next()
send用法,注意get为参数和return的结果,无需单独写return
#coding=utf-8 from time import sleep def test(): get='' while True: l = yield get if l: print l sleep(2) get= 'result:%s' % l else: return l1=[1,2,3,4,5] t=test() t.send(None) for l in l1: r= t.send(str(l)) print r