I can think of two possibilities.
- You are running 2.x on Windows, the file contains about 3x as many '\r' characters as recognized '\r\n' or '\n' line endings, and EmEditor recognizes '\r' as a line ending, as does Python 3.x. Or something similar is happening with 2.7 on another OS.
Explanation: you open the file in text mode. 3.x uses OS-independent universal newlines are used and '\r' and '\r\n' are converted to '\n'. 2.x uses OS-dependent reading and on Windows, only '\r\n' is used.
Example:
with open('tem.dat', 'wb') as f:
f.write(b'a\rb\r\nc\n\rd\n')
with open('tem.dat', 'r') as f:
for i, t in enumerate(f):
print(i, t, repr(t[-1]))
3.x prints
0 a
'\n'
1 b
'\n'
2 c
'\n'
3
'\n'
4 d
'\n'
2.x prints
(0, 'a\rb\n', "'\\n'")
(1, 'c\n', "'\\n'")
(2, '\rd\n', "'\\n'")
Diagnosis: add to your code "if '\r' in fline: print(fline)" before processing.
- There is something in the file that Python sees as End-of-File and EmEditor does not. Diagnosis. Add 'length = 0' before the loop and 'length += len(fline)' in the loop and see if it is at least approximately right after.