For some large file,
lines_a = len(fa.readlines())
print(lines_a)
And for Bash (on Mac):
wc -l
the result are different!
What is the possible reason?
For some large file,
lines_a = len(fa.readlines())
print(lines_a)
And for Bash (on Mac):
wc -l
the result are different!
What is the possible reason?
Just mention that I met similar problem when I was doing machine translation task. The main reason that the line number is not right, maybe because you have not open the file in 'b' mode. So try to
with open('some file', 'rb') as f:
print(len(f.readlines()))
You will get the same number as wc -l
This could also happen if you have \r in your text file.
When reading input from the stream, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller.
^ from python textiowrapper documentation.