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))
posted @ 2021-10-05 20:30  石棠  阅读(36)  评论(0编辑  收藏  举报