I am having trouble getting python to read specific lines. What i'm working on is something like this:
lines of data not needed
lines of data not needed
lines of data not needed
--------------------------------------
***** REPORT 1 *****
--------------------------------------
[key] lines of interest are here
[key] lines of interest are here
[key] lines of interest are here
[key] lines of interest are here
[key] lines of interest are here #This can also be the EOF
--------------------------------------
***** REPORT 2 *****
--------------------------------------
lines of data not needed
lines of data not needed
lines of data not needed #Or this will be the EOF
What I've attempted was something such as:
flist = open("filename.txt").readlines()
for line in flist:
if line.startswith("\t**** Report 1"):
break
for line in flist:
if line.startswith("\t**** Report 2"):
break
if line.startswith("[key]"):
#do stuff with data
However, I have a problem when the file ends without a end delimiter... Such as when report #2 is not displayed. What is a better approach?