我只想在文件中写入异常详细信息:我尝试如下“
def WriteErrorLog(e) :
global lcnt
lstErr=[]
iUrlfOutputFile = open("C:\Error.log", "a")
csvUrlfInfoWriter = csv.writer(iUrlfOutputFile, delimiter=',', lineterminator='\n')
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
csvUrlfInfoWriter.writerow('[Exc_Type, FileName, Script_Line No,InputFile_LineNo]')
lstErr.append(exc_type)
lstErr.append(fname)
lstErr.append(g_lcnt)
for value in lstErr :
csvUrlfInfoWriter.writerow(value)
iUrlfOutputFile.close()
在除了块:
except Exception as e :
WriteErrorLog(e)
它不起作用,有人可以纠正我吗?或者可以提出任何更好的选择?谢谢!!