Guest User

Untitled

a guest
Jun 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. # fast pythonic way to count the number of lines in a textfile
  2. # this function correctly distincts between the number of linebreaks and the number of lines
  3. def file_len(filename):
  4. count = 0 # handle completely empty files
  5. with open(filename, 'r') as file:
  6. for count, _ in enumerate(file, 1):
  7. pass
  8. return count
Add Comment
Please, Sign In to add comment