在CSV Wri中替换\r\n for

2024-10-01 17:33:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在用python打开和编写一个CSV文件:

with open('Data.csv', 'wb') as redata_csv:
    csv_writer = csv.writer(redata_csv, delimiter=',')

但是,每一行新行都以\r\n结尾,我希望它只以\n结尾。我不知道怎么。。。在


Tags: 文件csvdataaswith结尾openwriter
2条回答
csv.writer(reindentified_csv, delimiter=',', lineterminator='\n')

csv.writer Documentation

csv.writer(csvfile, dialect='excel', **fmtparams)

...

The other optional fmtparams keyword arguments can be given to override individual formatting parameters in the current dialect.

Dialects and Formatting Parameters

lineterminator

The string used to terminate lines produced by the writer. It defaults to '\r\n'.

使用^{}关键字参数。在

readerwriter类都支持通过关键字参数创建自定义匿名方言。您已经通过设置delimiter-添加lineterminator获得一个匿名方言,该方言由逗号分隔,并由换行符终止。在

相关问题 更多 >

    热门问题