0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python csv パッケージの改行コードを指定しても CRLF になる

Last updated at Posted at 2022-04-19

目標:CRLF ではなく、 LF にしたい。

import csv

(中略)

with open("output.tsv", "w", encoding='utf-8', newline="\n") as f:
    writer = csv.writer(f, delimiter='\t', lineterminator="\n")
    writer.writerow(['key', 'value'])
    writer.writerows(data)

基本的にはnewline="\n"でよいはず。しかし LF にならない。

なぜか、openwriterのどちらも改行コードを"\n"に指定しないと、CRLFになってしまう。

参考リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?