1
我在創建csv文件的內容時顯示爲打印輸出時遇到問題。編輯csv文件Python 3 - 將文件內容與打印輸出相匹配
代碼:
import csv
with open('test.csv', 'w', newline='') as csvfile:
filewriter = csv.writer(csvfile, delimiter=' ',
quotechar=',', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Spam'] * 2 + ['Baked Beans'])
filewriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
with open('test.csv', newline='') as csvfile:
filereader = csv.reader(csvfile, delimiter=' ', quotechar=',')
for row in filereader:
print(', '.join(row))
輸出:
Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam
test.csv
文件:
Spam Spam ,Baked Beans,
Spam ,Lovely Spam, ,Wonderful Spam,
通知怪異的逗號。
的test.csv
Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam