至少有5种方法可以在python中打印异常信息。
except Exception as e:
print(e)
print(str(e))
print(e.what())
print('{}'.format(e))
print(pformat(e))
正确的方法是什么,什么是pythonic?
答案 0 :(得分:1)
在捕获异常后使用回溯:
import traceback
traceback.print_exc()
答案 1 :(得分:-1)
except Exception as e:
print(e)
使用下面的链接获取更多示例 https://www.pythonforbeginners.com/error-handling/exception-handling-in-python