热线电话:13121318867

登录
2019-02-15 阅读量: 808
python try...except中如何输入e的行号

python try...except中如何输入e的行号?

try:
print(aaa)
except Exc eption as e:
print (e)

答:举例来说

import sys, os
try:
raise NotImplementedError("No error")
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
0.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子