Splitting text into lines

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

> Are repeated newlines/carriage returns significant at all? What about
> just using re and just replacing any repeated instances of '\r' or '\n'
> with '\n'? I.e. something like
>  >>> # the_string is your file all read in
>  >>> import re
>  >>> re.sub("[\r\n]+", "\n", the_string)
> and then continuing as before (i.e. splitting by newlines, etc.)
> Does that work?
> Cheers,
> Thomas

The '\r\r\n' string is a line separator, though not used consistently in US
meteorological bulletins. I do not want to eliminate "real" empty lines.
I was hoping there is a way to prevent read() from making hidden changes to
the file content.


More information about the Python-list mailing list