消除行

时间:2016-09-26 13:23:25

标签: python python-2.7

我想消除一排又一行的空白差距!请参阅图片以获得更好的概述。代码有什么问题?从excel查看时,记事本格式似乎很好,每个条目都会出现空格,包括标题输入后的第一次

1 个答案:

答案 0 :(得分:1)

取决于您使用的python版本:

# Python 2
with open('/pythonwork/thefile_subset11.csv', 'wb') as outfile:
    writer = csv.writer(outfile)

# Python 3
with open('/pythonwork/thefile_subset11.csv', 'w', newline='') as outfile:
    writer = csv.writer(outfile)

致记:https://stackoverflow.com/a/3348664/5415084

因此,总结一下:在使用newline=''参数时,python 3需要一个额外的参数w,而在打开文件时,python 2需要wb参数。

相关问题