kkhhhkk
Coder
I have a data file with has lines that look like this:
input
lines
lines
optimized
input
lines
lines
input
lines
lines
optimized
I want my script to go through this file, find the lines with input, find the line with optmized and write all the lines between them but only if its input lines lines optmized as opposed to input lines lines input lines lines optmized (basically for the above example input lines lines optmized should only write twice)
I have the following code, however it only prints the lines with optimized, how can I alter it to do what I intend it to?
input
lines
lines
optimized
input
lines
lines
input
lines
lines
optimized
I want my script to go through this file, find the lines with input, find the line with optmized and write all the lines between them but only if its input lines lines optmized as opposed to input lines lines input lines lines optmized (basically for the above example input lines lines optmized should only write twice)
I have the following code, however it only prints the lines with optimized, how can I alter it to do what I intend it to?
Python:
writefile = open("input_two.txt","a")
skip_line = True
with open("input_n.txt","r") as myfile:
skip_line = True
for line in myfile:
if "Input" in line:
next_skip_line = False
elif "Optimized" in line:
next_skip_line = True
if not skip_line and next_skip_line:
writefile.write(line)
skip_line = next_skip_line