python中异常的保存及断言(用到traceback,assert)
"""
异常信息保存到文件中
"""
import traceback
try:
raise Exception('This is the error message.')
except:
errorFile = open('errorInfo.txt', 'w')
errorFile.write(traceback.format_exc())
errorFile.close()
print('The traceback info was written to errorInfo.txt')
"""
断言 assert 条件,条件为False是显示的字符串
"""
a = 'open'
assert a == '123', 'a != 123'