Extraer valores entre dos cadenas en un archivo de texto
Digamos que tengo un archivo de texto con el contenido a continuación
fdsjhgjhg
fdshkjhk
Start
Good Morning
Hello World
End
dashjkhjk
dsfjkhk
Start
hgjkkl
dfghjjk
fghjjj
Start
Good Evening
Good
End
Escribí el siguiente código:
infile = open('test.txt','r')
outfile= open('testt.txt','w')
copy = False
for line in infile:
if line.strip() == "Start":
copy = True
elif line.strip() == "End":
copy = False
elif copy:
outfile.write(line)
Tengo este resultado en outfile:
Good Morning
Hello World
hgjkkl
dfghjjk
fghjjj
Good Evening
Good
Mi problema es que quiero tomar solo los datos entre el inicio y el final, pero no entre el inicio y el inicio o el final y el final