How to get line count of a large file cheaply in Python? by Tarik One line, probably pretty fast: num_lines = sum(1 for line in open('myfile.txt'))