def init(func):
    def wrapper(*args,**kwargs):
        obj = func(*args,**kwargs)
        next(obj)
        return obj
    return wrapper


@init
def food(name):
    print("%s start to eat" % name)
    food_list = []
    while True:
        food = yield food_list
        food_list.append(food)
        print("%s eat %s" % (name,food_list))


e = food("xyp")     # xyp start to eat
e.send("apple")     # xyp eat ['apple']
e.send("apple")     # xyp eat ['apple', 'apple']
e.send("apple")     # xyp eat ['apple', 'apple', 'apple']
......
协程 吃包子

相关文章:

  • 2021-08-28
  • 2021-08-30
  • 2022-03-09
  • 2022-12-23
  • 2021-04-27
  • 2021-04-12
  • 2021-09-22
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2021-11-17
  • 2021-06-30
相关资源
相似解决方案