내 csv 파일을 xml 파일의 txt 버전으로 변환하는 코드가 있습니다. 폴더의 모든 파일을 변환하려면 어떻게 편집해야합니까?Python 폴더의 모든 csv 파일을 txt로 변환
import csv
csvFile = 'path\to\input\123.csv'
xmlFile = 'path\to\output\123.txt'
csvData = csv.reader(open(csvFile))
xmlData = open(xmlFile, 'w')
rowNum = 0
for row in csvData:
if rowNum == 0:
tags = row
# replace spaces w/ underscores in tag names
for i in range(len(tags)):
tags[i] = tags[i].replace(' ', '_')
else:
xmlData.write('<products_joined>' + "\n")
for i in range(len(tags)):
xmlData.write(' ' + '<' + tags[i] + '><![CDATA[' \
+ row[i] + ']]></' + tags[i] + '>' + "\n")
xmlData.write('</products_joined>' + "\n")
rowNum +=1
xmlData.close()
가능한 중복 http://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt -in-python) – JazZ