其他分享
首页 > 其他分享> > list2Txt.py

list2Txt.py

作者:互联网

import os
import logging
import datetime
from DataCleaning.library.functions.appendString2Txt import *
from DataCleaning.library.functions.createTxt import *
from DataCleaning.library.functions.processBar import *

def list2Txt(tempListAll, outputFileName, wd='', sep = "|", inputPercentage = -1, newFile = False):
# startTime = datetime.datetime.now()
tempWd = os.getcwd()
if wd != '':
os.chdir(wd)
if newFile:
createTxt("", outputFileName, wd)
strLine = ''
for i in range(len(tempListAll)):
strLine += sep.join(tempListAll[i]) + '\n'
if inputPercentage != -1:
processBar(i, len(tempListAll), inputPercentage=inputPercentage)
else:
processBar(i, len(tempListAll))
if i % 10000 == 0:
strLine = strLine.replace("'", "''")
appendString2Txt(strLine, outputFileName, wd)
strLine = ""
strLine = strLine.replace("'", "''").strip()
appendString2Txt(strLine, outputFileName, wd)
os.chdir(tempWd)
# endTime = datetime.datetime.now()
# logging.info("time spent on generating " + str(len(tempListAll)) + " lines in " + outputFileName + ": " + str(endTime - startTime))

标签:wd,tempListAll,py,outputFileName,datetime,inputPercentage,list2Txt,strLine
来源: https://www.cnblogs.com/zhulimin/p/15369485.html