基于python异常的回调
smoothie的Python项目详细描述
基于python异常的回调
将回调添加到指定为 根据引发的异常调用。
fromsmoothie.kingimportDispenserdeferr_callback(*args,**kwargs):print("Error handled")juice=Dispenser()@juice.attach(exception=IndexError,callback=err_callback)defvending_machine():drinks=['Tea','Coffee','Water']returndrinks[4]vending_machine()
要运行单元测试,
pip install -r test-requirements.txt cd smoothie/tests nosetests -vs``