【发布时间】:2016-01-17 02:30:09
【问题描述】:
我有一些代码,每当遇到这样的异常时,我都想从中获取电子邮件。
try:
f(**kwargs)
except Exception as e:
# email me the environment
我知道 Python 装饰器可以为此工作,例如:
@check_error
def f()
@check_error
def g()
如果我希望我的模块中的每个代码都被默认包装怎么办?喜欢
def f() 没有@check_error,但我仍然希望能够实现这一点。
理想情况下,该解决方案应适用于函数和类方法。
【问题讨论】:
标签: python decorator python-decorators