Reputation: 17392
I've a json file and this file will be updated every 5 mins or so. Initially I parse the file from the starting point. Now I need to parse this json file after every 15 to 20 mins. Is there any way of storing the pointer kind of thing which will store the last line of the file parsed and when again after 15/20 mins I need to parse the file it should start from that pointer(Since parsing the same data(historical data) would be highly inefficient and would make my process go slow)?
Upvotes: 1
Views: 376
Reputation: 1424
Use tell() method of file(after reading from file) this will return current pointer. And next time you read use seek() function of file for setting pointer to old position.
Example:
f = open("test.json" , "w+")
.....
.....
your code for reading
f.read()
.....
.....
last_position = f.tell() # return current position of file pointer(where you stoped reading)
now when you next time read from file use seek() function
f = open("test.json" , "w+")
f.seek(last_position)
f.read() # now this will start reading from last position
Hope This will Help :)
Upvotes: 2