【发布时间】:2018-10-05 13:12:53
【问题描述】:
我知道我可以在 python 中捕获异常,例如:
try:
with open('file.log') as file:
read_data = file.read()
except:
print('Exception!')
但是如何获取异常类型或错误信息呢?
【问题讨论】:
标签: python
我知道我可以在 python 中捕获异常,例如:
try:
with open('file.log') as file:
read_data = file.read()
except:
print('Exception!')
但是如何获取异常类型或错误信息呢?
【问题讨论】:
标签: python
try:
with open('file.log') as file:
read_data = file.read()
except Exception as e:
print(e)
您必须将异常转换为变量。 Python documentation.
【讨论】: