I am reposting my old question with an improved description, as I feel that it was mistakenly marked as a duplicate and thus closed due to poor explanation.
I am trying to mark a specific line to be my 'checkpoint', so that everytime my condition is satisfied, the program will go back to that checkpoint and read lines starting from there. I am unsure of how to do this.
This is my current code, which doesn't solve the problem (In this context, I am trying to search for a FLAG followed by a line containing a stock name(stocklist[k] and NysImbClearPrice, then I do something with it and extract that. then I go back to FLAG to read the lines again, this time searching for a line containing a different stock name):
with open('loggerdec7.log', 'r') as rf:
found = False
k = 0
for line in rf:
if 'FLAG' in line:
spot = rf.tell() #mark specified checkpoint
found = True
if found:
nameandnysimb = [stocklist[k], 'NysImbClearPrice:']
if all(x in line for x in nameandnysimb):
k+=1
clearprice = line.split('NysImbClearPrice: ',1)[-1].split(' ',1)[0]
cplist.append(clearprice)
rf.seek(spot) #relocate to specified checkpoint
Thanks and appreciate all the help!