Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fast pythonic way to count the number of lines in a textfile
- # this function correctly distincts between the number of linebreaks and the number of lines
- def file_len(filename):
- count = 0 # handle completely empty files
- with open(filename, 'r') as file:
- for count, _ in enumerate(file, 1):
- pass
- return count
Add Comment
Please, Sign In to add comment