Created
April 3, 2016 21:24
-
-
Save nerflad/041daaf7f0f1899c51d49e9c8ff32069 to your computer and use it in GitHub Desktop.
Python 2: Get file linecount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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