Unable to read the output file. The code seems perfect, but neither im getting desire result nor im getting an error. Please help me on this
Note: I'm getting the result as blank space as i print
with open("D:/txt_res/RahulChoudhary.txt") as infile, open ("x", 'w') as outfile:
copy = False
for line in infile:
if line.strip() == "Technical Skills":
copy = True
elif line.strip() == "Work Experience":
copy = False
elif copy:
outfile.write(line)
infile = open("x", 'r')
contents = infile.read()
print(contents)
Based on your specified requirements in the comments, I've updated my code. It searches for "Technical Skills" in each line, and once found, enables writing (
copy
). It will write every line once this one is hit, and when a line with "Work Experience" is found, it stops processing.Given this input:
It will produce this output:
If you don't want the "Technical Skills" line in the output, put a line with
continue
directly after thecopy = True
line.