Splitting text into lines

George Trojan - NOAA Federal george.trojan at noaa.gov
Tue Dec 13 12:39:24 EST 2016


>
> Tell Python to keep the newline chars as seen with
> open(filename, newline="")
> For example:
> >>>
> * open("odd-newlines.txt", "rb").read() *
> b'alpha\nbeta\r\r\ngamma\r\r\ndelta\n'
> >>>
> * open("odd-newlines.txt", "r", newline="").read().replace("\r", *
> "").splitlines()
> ['alpha', 'beta', 'gamma', 'delta']


Thanks Peter. That's what I needed.

George


More information about the Python-list mailing list