环境
Python 3.7
代码
try:
pass
except Exception as e:
print('error: {0}, file: {1}, line: {2}'.format(
e,
e.__traceback__.tb_frame.f_globals["__file__"], # 发生异常所在的文件
e.__traceback__.tb_lineno # 发生异常所在的行
)
)
Python 3.7
try:
pass
except Exception as e:
print('error: {0}, file: {1}, line: {2}'.format(
e,
e.__traceback__.tb_frame.f_globals["__file__"], # 发生异常所在的文件
e.__traceback__.tb_lineno # 发生异常所在的行
)
)