在Python 2中,请outfile使用模式
'wb'而不是来打开
'w'。该
csv.writer写入
rn直接到文件中。如果你未以二进制模式打开文件,它将写入,
rrn因为在Windows 文本模式下会将每个文件
n转换为
rn。
在Python 3中,所需的语法已更改(请参见下面的文档链接),因此请改用
outfile其他参数
newline=''(空字符串)打开。
例子:
# Python 2with open('/pythonwork/thefile_subset11.csv', 'wb') as outfile: writer = csv.writer(outfile)# Python 3with open('/pythonwork/thefile_subset11.csv', 'w', newline='') as outfile: writer = csv.writer(outfile)


