Can you jump to a line with file operations in python?

I am parsing the file and should keep track of where I am in the file ... let's say I have a test.txt file and I make a while loop that constantly reads the data as each line is written to the file. In the event of a failure, I mark my position in another file using the tell () method of the file. Is there a way to mark a line and return to that line position or do I need to track bytes with a message only?

#this is just example code, not the real thing
f = open('test.txt')
pos = open('pos.txt', 'w')
f.seek(pos)
while 1:
  readline(f)
  pos.write(f.tell())

Update: files about 1 GB each

+3
source share
2 answers

You may like it better: http://docs.python.org/library/linecache.html

"In the event of a failure, I mark my position in another file using the tell () method of the file."

Good.

" "

. tell. tell - , seek.

, , , . , tell - "" , .

+2

, f.tell() ( , ), .

, , .

+1

Source: https://habr.com/ru/post/1735116/


All Articles