def line_count(path): count = 0 with open(path) as lines: for count, l in enumerate(lines, start=1): pass return count