I have a large file (6-60 GB) that I cannot load entirely into memory. I can read it line by line:
with open(...) as f:
for line in f:
# Do something with 'line'
But sometimes when I've read say the nth line, I need information from the n+2th line as well. How do I read this n+2th line while my 'line' object is pointing to the nth line? I will still need to process the later line normally.
I'm worried if I use f.readlines(10), since I don't know the size of my look-ahead (it could be 99).
I thought of one way, which would be having line pointers for each line with seek and tell in a list, but I'm worried about storage space again.
I'm looking for speed over all else in reading this file. Any suggestions?