0

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!

ppwater
  • 2,315
  • 4
  • 15
  • 29
gubith
  • 13
  • 3
  • Could you also add how this code currently behaves? – ssp Dec 20 '20 at 11:37
  • Maybe this [How to solve “OSError: telling position disabled by next() call”](https://stackoverflow.com/questions/29618936/how-to-solve-oserror-telling-position-disabled-by-next-call) helps (last answer). – Timus Dec 20 '20 at 18:57

0 Answers0