If the file is otherwise stable, use fileobj.tell()
to remember your position in the file, then next time use fileobj.seek(pos)
to return to that same position in the file.
This only works if you do not use the fileobject as an iterator (no for line in fileobject)
or next(fileobject)
) as that uses a read-ahead buffer that will obscure the exact position.
Instead, use:
for line in iter(fileobj.readline, ''):
to still use fileobj
in an iteration context.