I have written a code that reads a file, finds if a line has the word table_begin
and then counts the number of lines until the line with the word table_end
.
Here is my code -
for line in read_file:
if "table_begin" in line:
k=read_file.index(line)
if 'table_end' in line:
k1=read_file.index(line)
break
count=k1-k
if count<10:
q.write(file)
I have to run it on ~15K files so, since its a bit slow (~1 file/sec), I was wondering if I am doing something inefficient. I was not able to find myself, so any help would be great!