改行コードについて (Python編)
整理
Python での デフォルト 改行コード
- 読み込み時 : 強制的に '\n' に変換される
- 書き込み時 : OS によって異なる (Win: '\r\n', Mac/Linux: '\n')
明示するコード零
読み込み
py
with open(path, encoding='utf-8') as f:
書き込み
py
with open(path, 'w', encoding='utf-8', newline='\n') as f:
以下広告