try:print(a)except Exception as e:print(e)print(e.__traceback__.tb_frame.f_globals["__file__"]) # the file where the exception occurredprint(e.__traceback__.tb_lineno) # the line number where the exception occurred
References
https://blog.csdn.net/little_stick_i/article/details/120973526