...without reading the whole file into memory at once.
I currently have this:
def get_file_stats(input_file: pathlib.Path):
with input_file.open() as f:
line_count = 0
word_count = 0
character_count = 0
for line in f.readlines():
line_count += 1
word_count += len(line.split())
character_count += len(line)
return {"input_file": input_file, "byte_count": input_file.stat().st_size,
"line_count": line_count, "word_count": word_count,
"character_count": character_count}
and the character_count ends up being wrong because the line endings get stripped out by f.readlines(). What's the smartest way to fix this while accounting for the possibility of both \n and \r\n line endings?
