python - How to read a file from the last read position? -


i have 3,000,000,000 line text file. use command below open

with open("/data/tmp/tbl_show_follow.txt") infile: 

but need kill python scripts stop reading file, , next time need read last position read. current solution using counter_i remember position , print log every 100,000 lines

20161108 21:19  last position : 100000 20161108 22:34  last position : 200000 20161108 23:34  last position : 300000 ....... 20161408 23:34  last position : 200000000 

and run python scripts again, need change condition

count_i = 0  open("/data/tmp/tbl_show_follow.txt") infile:     line in infile:         if count_i > 300000:             sth ... 

but if last position 200,000,000 , stop python script, next time need read file beginning , count 1 200,000,000. think stupid that, how begin 200,000,000th line? there method remember last position read file?

you can use file.tell() file’s current position (measured in bytes) , file.seek() set it.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -