def init(func): #初始化 def wrapper(*args,**kwargs): g=func(*args,**kwargs) next(g) return g return wrapper @init def eater(name): print(‘%s 准备开始吃饭啦‘ %name) food_list=[] while True: food=yield food_list print(‘%s 吃了 %s‘ % (name,food)) food_list.append(food) g=eater(‘egon‘) g.send(‘蒸羊羔‘)
原文地址:https://www.cnblogs.com/xiongrongqin/p/8179264.html
时间: 2024-10-02 09:35:34