traceback.print_exc()打印到文件
作者:互联网
try:
pass
except Exception as e:
trace_file=open(trace_file_path, 'a')
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),file=trace_file)#记录报错的时间
traceback.print_exc(file=trace_file)#输出报错到文件
trace_file.close()
traceback.print_exc()#打印报错(如果不加这一行则只输出到文件)
标签:exc,trace,traceback,报错,file,print 来源: https://blog.csdn.net/lycwhu/article/details/121534892