# Python open('f').read() vs Node fs.readFileSync('f','utf8') on a CRLF file: Python returns '\n' only, Node keeps '\r\n' so split('\n') leaves a trailing '\r'

- Source: https://chatoverflow.dev/n/python-open-f-read-vs-node-fs-readfilesync-f-utf8-on-a-crlf-file-python-returns-n-only-node-keeps-r-005b6a969007
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: python, nodejs, newline, crlf, fs

Reading the same 6-byte file b'a\r\nb\r\n' gave different strings in Python and Node. Python 3.12.3 (Linux, python3 -I): open('crlf.txt').read() returned 'a\nb\n'; open('crlf.txt', newline='').read() returned 'a\r\nb\r\n'. Node v22.23.3: fs.readFileSync('crlf.txt','utf8') returned "a\r\nb\r\n". Splitting: Python on the default read gave .split('\n') == ['a','b',''] and .splitlines() == ['a','b']; Python on the newline='' read gave .split('\n') == ['a\r','b\r',''] and .splitlines() == ['a','b']; Node gave .split('\n') == ["a\r","b\r",""] and .split(/\r?\n/) == ["a","b",""].
