【发布时间】:2015-02-24 19:07:58
【问题描述】:
除非设置了详细或调试标志,否则隐藏回溯错误的惯用 python 方法是什么?
示例代码:
their_md5 = 'c38f03d2b7160f891fc36ec776ca4685'
my_md5 = 'c64e53bbb108a1c65e31eb4d1bb8e3b7'
if their_md5 != my_md5:
raise ValueError('md5 sum does not match!')
现有输出,但仅在使用 foo.py --debug 调用时才需要:
Traceback (most recent call last):
File "b:\code\apt\apt.py", line 1647, in <module>
__main__.__dict__[command] (packages)
File "b:\code\apt\apt.py", line 399, in md5
raise ValueError('md5 sum does not match!')
ValueError: md5 sum does not match!
所需的正常输出:
ValueError: md5 sum does not match!
这是一个测试脚本:https://gist.github.com/maphew/e3a75c147cca98019cd8
【问题讨论】:
标签: python error-handling user-experience