I'm trying to read through a very large text file (> 1.5gb) line by line but would like to avoid loading the whole file into memory, is there a way to just read a specific line at once without loading everything first?
To read every line one by one you can do
with open('file.txt') as file:
for line in file:
print(line)
Actually when you open
a file, you will just get a file handle of the file. The file is never fully loaded in memory unless you specifically want to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With