Python try...except...时捕获异常时具体文件和行数
1 |
|
模拟一段会抛出异常的代码
执行结果:
division by zero
C:/Users/admin01/Desktop/script/demo.py
4
可以看到报错原因为division by zero
文件位置为C:/Users/admin01/Desktop/script/demo.py
行数为第4行
要是系统中不能实时打印出来的话,可以考虑加上 flush=True
1 |
|
Python try...except...时捕获异常时具体文件和行数
https://waym1ng.github.io/2021/07/08/Python try...except...时捕获异常时具体文件和行数/