I have a BIG text file (100 000+ lines) from which I would like to have a loop that always opens the file, gets the first line of text (In this case it is a number), and then deletes that first line, so the next time the file is opened again, the first line is not the same. I have tried to do it so that the line number is always saved in a file and then it iterates to that specific line of the text file, but I believe this is not the most efficient way...
my text file consists of number like this:
1234
2212
3453
1232
... (and it goes on for ages)
The code I have attempted is:
with open('line_number.txt', 'rb') as inp:
line = inp.read()
fp = open("list.txt")
for i, line in enumerate(fp):
if i == line - 1: #iterates until the number match
s = i + 1
with open('new.txt', 'w') as outp:
outp.write(s)
outp.close()
print(i)
break
fp.close()
Is there a more efficient way to do this to large files? I believe iterating until the line I need is really time-inefficient...