I am trying to read sections of a file into numpy arrays that have similar start and stop flags for the different sections of the file. At the moment I have found a method that works, but for only one section of the input file before needing to re open the input file.
My code at the moment is:
with open("myFile.txt") as f:
array = []
parsing = False
for line in f:
if line.startswith('stop flag'):
parsing = False
if parsing:
#do things to the data
if line.startswith('start flag'):
parsing = True
I found the code from this question
With this code I need to re-open and read through the file.
Is there a way to read all sections without having to open the file for each section to be read?