I am looking for a way to efficiently find the number of lines in a text file. I am iterating through files, but each file has a different number of lines.
with open(filename) as fin:
for line in islice(fin, 5, 100000000):
lines.append(line)
Instead of putting a huge number to make sure I include all the lines, is there a better way to read how many lines are in the file?