I need to get the value of the previous line in a file and compare it with the current line as I'm iterating through the file. The file is HUGE so I can't read it whole or randomly accessing a line number with linecache
because the library function still reads the whole file into memory anyway.
EDIT I'm so sorry I forgot the mention that I have to read the file backwardly.
EDIT2
I have tried the following:
f = open("filename", "r")
for line in reversed(f.readlines()): # this doesn't work because there are too many lines to read into memory
line = linecache.getline("filename", num_line) # this also doesn't work due to the same problem above.