Opening the file in binary mode will avoid this in Py2 on Windows. However, in Py3 (and in Py2.6 +, if you use io.open
instead of the built-in one), binary mode in text mode means something clearly defined and platform independent and does not affect universal newlines. Instead, you can:
file = open(filename, 'r', newline='')
And newline will not be normalized.
source share