Getting exception details in Python

前端 未结 4 827
故里飘歌
故里飘歌 2021-02-04 00:04

I have to open & write to about 10 different files all within the same loop. e.g:

for i in range(0,10):
    try:
        a=5
        file1 = open(\"file1.txt         


        
4条回答
  •  情话喂你
    2021-02-04 00:50

    When using exc_type, value, exc_traceback = sys.exc_info(), note that the filename that generated the exception can be obtained through the following:

    exc_traceback.tb_frame.f_locals.get('filename')
    

提交回复
热议问题