【发布时间】:2018-04-03 21:24:57
【问题描述】:
当我使用 excel 2010 打开文件 test.csv 时,我在 python 3.6.4 中有这个简单的程序在 csv 文件中写入数据,我发现结果是这样写的:
这是程序:
import csv
lol = [(1,2,3),(4,5,6),(7,8,9)]
item_length = len(lol[0])
with open('test.csv', 'w') as test_file:
file_writer = csv.writer(test_file)
for i in range(item_length):
file_writer.writerow([x[i] for x in lol])
【问题讨论】:
-
但它们真的存在于 CSV 文件中吗?
-
听起来 Excel 使用的换行约定与文件中实际存在的换行约定不同。
-
不,文件是 w 模式,所以它是新的
-
文件为空文件中没有任何内容