currentReadPos = 0
removedLinesLength = 0
for line in file:
    currentReadPos = file.tell()
if remove(line):
    removedLinesLength += len(line)
else:
    file.seek(file.tell() - removedLinesLength)
file.write(line + '\n')
file.flush()
file.seek(currentReadPos)
How do I remove lines from a big file in Python, within limited environment