def _make_gen(reader):
    b = reader(1024 * 1024)
while b:
    yield b
b = reader(1024 * 1024)

def rawpycount(filename):
    f = open(filename, 'rb')
f_gen = _make_gen(f.raw.read)
return sum(buf.count('\n') for buf in f_gen)
how to count the total number of lines in a text file using python