Text file with mixed end-of-line terminations

woooee woooee at gmail.com
Thu Sep 1 15:17:37 EDT 2011

You can use f.read() to read the entire file's contents into a string,
providing the file isn't huge.  Then, split on "\r" and replace "\n"
when found.
A simple test:
input_data = "abc\rdef\rghi\r\njkl\r\nmno\r\n"
first_split = input_data.split("\r")
for rec in first_split:
    rec = rec.replace("\n", "")
    print rec

More information about the Python-list mailing list