I have a function that reads a large .txt file, line by line.
As parameter I give to the function the line index from where it should start reading in file.
First I call the function with 0 so that it will begin from the start. At the end I call again the function with a new parameter, but when it reenters in the function the fresh sent index (which is different now) is still 0 in the for statement. :(
from __future__ import print_function
import os
import sys
file = open("file.txt").read().splitlines()
for i, line in enumerate(file):
if file[i] == "@@@TC_FIN@@@":
fin = i;
#print (fin)
def AssembleTC(index):
while index < fin:
for index, line in enumerate(file):
if "@@@ ID:" in line:
print(file[index+1])
break
for index, line in enumerate(file):
if file[index] == "@@@TC_FIN@@@":
recursive = index;
#print (recursive)
break
AssembleTC(recursive+1)
AssembleTC(0)
It is vital for me to keep the present for statement with file[index] access procedure. I've read that I could skip lines with something like file.next()
but it doesn't work.
Is there any way to skip the number of lines that I want or simply to start the new reading from the updated index? Python 2.7.13 - Thank you!