SyntaxFix
Write A Post
Hire A Developer
Questions
This code is shorter and clearer. It's probably the best way:
num_lines = open('yourfile.ext').read().count('\n')