Text file with mixed end-of-line terminations

Alex van der Spek zdoor at xs4all.nl
Wed Aug 31 21:37:11 CEST 2011

I have a text file that uses both '\r' and '\r\n' end-of-line terminations.

The '\r' terminates the first 25 lines or so, the remainder is termiated 
with '\r\n'

Reading this file like this:

for line in open(filename,'r'):
    line= #Do whatever needs doing...

The first line read is actually a string consiting of the first 25 lines.
The readline() method does the same thing.

Is there a way to make it read one line at a time, regardless of the line 

By the way, the newlines attribute reports None after reading a few lines. I 
tried on Linux and Windows. I use the standard binaries as distributed.

Thanks in advance,
Alex van der Spek

More information about the Python-list mailing list