You compare lines with "\n" at the ends. You also continue, when you find the start marker.
beginOutput = false
with open("test.txt") as ff:
for line in ff:
if line.startswith('.Connect U5'):
beginOutput = true
if not beginOutput:
continue
if line.strip() == ".EndC":
break
print(line)
Note the strip()
. It's not the best solution, because it will strip all the lines in your file. Try to strip()
only the lines which start with .EndC
marker
* Be the first to Make Comment