line-count

(Python) Counting lines in a huge (>10GB) file as fast as possible

(Python) Counting lines in a huge (>10GB) file as fast as possible Question: I have a really simple script right now that counts lines in a text file using enumerate(): i = 0 f = open(“C:/Users/guest/Desktop/file.log”, “r”) for i, line in enumerate(f): pass print i + 1 f.close() This takes around 3 and a half …

Total answers: 5

How to get line count of a large file cheaply in Python?

How to get line count of a large file cheaply in Python? Question: How do I get a line count of a large file in the most memory- and time-efficient manner? def file_len(filename): with open(filename) as f: for i, _ in enumerate(f): pass return i + 1 Asked By: SilentGhost || Source Answers: You could …

Total answers: 44