【发布时间】:2016-01-25 22:05:42
【问题描述】:
这是一个 Python 类中的示例方法:
def publish_aggregate_account_group_stats(self, account_group_token):
message = {
"type": "metrics-aggregate-account-group-stats",
"accountGroupToken": account_group_token
}
try:
self._get_writer().write(message)
except:
self._put_cache(message)
我的类中有一些方法都运行try/except,我认为可以通过简单地创建一个为我处理这些的装饰器来干掉或清理它们。我只是不确定通过访问 self 装饰器的外观/工作方式。
【问题讨论】: