python try...except中如何输入e的行号?
try:
print(aaa)
except Exc eption as e:
print (e)
答:举例来说
import sys, ostry:
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)


雷达卡


京公网安备 11010802022788号







