I want to read a large file (>5GB), line by line, without loading its entire contents into memory. I cannot use readlines() since it creates a very large list in memory.
I want to read a large file (>5GB), line by line, without loading its
Share
Use a
forloop on a file object to read it line-by-line. Usewith open(...)to let a context manager ensure that the file is closed after reading: