当前位置: 移动技术网 > IT编程>脚本编程>Python > Python 装饰器装饰类中的方法(转)

Python 装饰器装饰类中的方法(转)

2018年02月08日  | 移动技术网IT编程  | 我要评论

超梦的逆袭国语,青春失乐园qvod,叶选宁3000伏兵名单

def catch_exception(origin_func):
def wrapper(self, *args, **kwargs):
try:
u = origin_func(self, *args, **kwargs)
return u
except Exception:
self.revive() #不用顾虑,直接调用原来的类的方法
return 'an Exception raised.'
return wrapper
class Test(object):
def init(self):
pass
def revive(self):
print('revive from exception.')
# do something to restore
@catch_exception
def read_value(self):
print('here I will do something.')
# do something.

原文地址:https://kingname.info/2017/04/17/decorate-for-method/

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网