with open("...txt") as fp:
for i, line in enumerate(fp):
if some condition :
i=0
fp.seek(0)
Text is huge, GBs of data so I use enumerate. I need to process this huge file several thousands of time so I decided to open it just at first time for efficiency. However although this code works, i
does not become 0 and it just goes on incrementing. I need that to be zero because I need position of lines i
. And it is just inefficient to multiply billions*several thousands everytime and make some modular arithmetic.
So my question is how can I set i
to be zero when I go back to the beginning of file? Thanks in advance (I use python 3.6)