我编写了一个程序来读取CSV文件并将内容作为插入语句输出。 然后我编写了一个执行程序,它应该获取CSV解析器程序的输出并将其写入.txt文件,但不是写入整个输出,而是只编写第一个语句。
这是执行者的代码:
import sys
with open('insert.txt', 'wb') as f:
subprocess.check_call(["python","CSVParserMultiple.py"], stdout=f)
以及解析器的代码:
import csv, os
path = 'C:/Users/user/Desktop/test/'
for file in os.listdir(path):
if file.endswith('.csv'):
# print ('Parsing file: ' + os.path.basename(path + file))
openFile = open(path + file)
csvFile = csv.reader(openFile)
getHeader = next(csvFile)
columnHeaders = map((lambda x:"'" + x +"'"), getHeader[:-1])
insert = 'INSERT INTO testing (' +"'ID', 'VehicleID'," + ', '.join(columnHeade