python - 修改csv.writer代码,使其不留空格

标签 python python-3.x

是否有任何方法可以修改以下代码,以便生成的 csv 由其派生列表的连续条目组成,垂直排列且仅由换行符分隔?

with open('timeSeries.csv','w') as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
    wr.writerows((x,) for x in timeSeries)

这会将列表 timeSeries 写入 csv,例如:

3

5

6

当我更喜欢简单的时候

3
5
6

但不确定到底要做什么改变。

最佳答案

我记得在使用 Windows 时遇到过这个问题...

尝试添加newline=""作为open的参数。这有帮助吗?

import csv

with open('timeSeries.csv','w',newline="") as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
    wr.writerows((x,) for x in timeSeries)

关于python - 修改csv.writer代码,使其不留空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58150873/

相关文章:

python-3.x - 使用 youtube-dl 搜索 Youtube 视频

python - 使用迭代器作为列和索引更快地将总和值附加到数据帧

python - Librosa 在 Docker 中引发了 OSError ('sndfile library not found' )

python - numpy 字符数组到字符串

Python 就地更新函数参数?

Python循环限制错误

python - Python 中的 Web 服务?

python - python中的反向DNS查找返回错误的主机

python - 在 Python 中从逗号分隔的字符串中仅提取某些字段的最快方法

python可以编码为utf-8但不能解码