Splitting text into lines
tomuxiong at gmx.com
Tue Dec 13 12:00:33 EST 2016
On 12/13/2016 08:45 AM, George Trojan - NOAA Federal wrote:
> Ideally I'd like to have code that handles both '\r\r\n' and '\n' as the
> split character.
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?
More information about the Python-list