Discuss / Python / 协程就是封装的很好用的回调函数

协程就是封装的很好用的回调函数

Topic source

猎杀属性

#1 Created at ... [Delete] [Delete and Lock User]

感觉协程就是把回调函数封装了下,计算机界造词能力果然很强QAQ

不一样的啊,consumer 在执行的时候他的局部变量值是保留的

def consumer():
    r = ''
    index = 1
    while True:
        n = yield r
        if not n:
            return
        print('[CONSUMER] Consuming %s...<index = %s>' % (n, index))
        r = '200 OK'
        index += index

你这样再看看就不一样了


  • 1

Reply