Skip to content

Instantly share code, notes, and snippets.

@nerflad
Created April 3, 2016 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerflad/041daaf7f0f1899c51d49e9c8ff32069 to your computer and use it in GitHub Desktop.
Save nerflad/041daaf7f0f1899c51d49e9c8ff32069 to your computer and use it in GitHub Desktop.
Python 2: Get file linecount
import os
def file_len(fname): #get file linecount
if os.stat(fname).st_size == 0:
return 0
with open(fname) as f:
for i, l in enumerate(f):
pass
return i+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment