0
我有這樣的代碼片段:合併的Unicode CSV文件,Python 2.7版
import csv, sys, os
rootdir = sys.argv[1]
for root,subFolders, files in os.walk(rootdir):
outfileName = rootdir + "\\root-dir.csv" # hardcoded path
#for subdir in subFolders:
for file in files:
filePath = os.path.join(root, file)
with open(filePath) as csvin:
readfile = csv.reader(csvin, delimiter=',')
with open(outfileName, 'a') as csvout:
writefile = csv.writer(csvout, delimiter=',', lineterminator='\n')
for row in readfile:
row.extend([file])
writefile.writerow(row)
csvout.close()
csvin.close()
print("Ready!")
它的偉大工程與ASCII文件,但不能使用Unicode版本。 以下是autoruns日誌文件的示例:https://cloud.mail.ru/public/6Gqc/MKjKaqs8B。我需要將一些這樣的文件合併到一個文件中。 如何更改此代碼以執行此操作?它需要爲python 2.7。
預先感謝您!
我試過使用它,但沒有正確讀取數據。當我試圖打開一個原始文件時,它會拋出一個錯誤:'utf8'編解碼器無法解碼位置0中的字節0xff。當我從文件的開頭刪除2個字節時,它會拋出一個錯誤:line包含空字節 – Oleg
@Oleg這聽起來像你的數據文件是UTF-16,而不是UTF-8。 –
也許,你是否打算閱讀閱讀UTF-16的方法? – Oleg