我在編寫一個python腳本時遇到了一些問題,以審覈我公司的許多不同應用程序中的所有CSV文件,而且我幾乎用概念帶給老闆,並炫耀我可以用python做什麼,但問題是,我不明白在python中的CSV類所有這一切以及......導出爲CSV將所有字符分隔爲字段
這是一個例子,計算機信息列表如下所示:
['EB-ABORTZ,True,False,False,0', 'EB-AGONCHAROVA,True,False,False,0',
'EB-AHART-1,True,False,False,0', 'EB-AHEIDENREICH,True,False,False,0',
'EB-ALOCKLEAR,True,False,False,0', 'EB-AMARGULIS,True,False,False,0',
'EB-ASKLAR,True,False,False,0', 'EB-ASKLAR-1,True,False,False,0',
'EB-ASKLAR-3,True,False,False,0', 'EB-BCHOW-1,True,False,False,0',
'EB-BJOHNSON,True,False,False,0', 'EB-BLYLE,True,False,False,0',
'EB-BRUSSUM,True,False,False,0', 'EB-CCLEARY,True,False,False,0',
'EB-...]
,這裏是什麼在最後的代碼會產生一個例子.....
"E","B","-","A","B","O","R","T","Z",",","T","r","u","e",",","F","a","l","s","e",",","F","a","l","s","e",",","0"
"E","B","-","A","G","O","N","C","H","A","R","O","V","A",",","T","r","u","e",",","F","a","l","s","e",",","F","a","l","s","e",",","0"
"E","B","-","A","H","A","R","T","-","1",",","T","r","u","e",",","F","a","l","s","e",",","F","a","l","s","e",",","0"
"E","B","-","A","H","E","I","D","E","N","R","E","I","C","H",",","T","r","u","e",",","F","a","l","s","e",",","F","a","l","s","e",",","0"
"E","B","-","A","L","O","C","K","L","E","A","R",",","T","r","u","e",",","F","a","l","s","e",",","F","a","l","s","e",",","0"
"E","B","-","A","M","A","R","G","U","L","I","S",",","T","r","u","e",",","F","a","l","s","e",",","F","a","l","s","e",",","0"
下面是我用來嘗試在事後將數據導出爲CSV格式的方法的副本。
def collate_computers(computers):
with open('results.csv', 'w', encoding='utf8',)as outfile:
writer = csv.writer(outfile, quoting=csv.QUOTE_ALL, delimiter=',')
for c in computers:
writer.writerow(c)
究竟是什麼問題了嗎?我可以正確使用你的代碼。什麼是您的預期輸出? – MaThMaX