python a fast way to count the number of lines in a file
# https://stackoverflow.com/questions/845058/how-to-get-line-count-of-a-large-file-cheaply-in-python/68385697#68385697 def count_lines_in_file_fast(fname): def _make_gen(reader): while True: b = reader(2 ** 16) if not b: break yield b with open(fname, "rb") as f: count = sum(buf.count(b"\n") for buf in _make_gen(f.raw.read)) return count















