I have text file. i want to open that text file and search one word called "OPR" if that word occured in the Final.txt file write 3 line of that particular string example code given below
text1="Some decoders allow you to manipulate the image reading"
text2="file.This can often be used to speed up decoding when creating"
text3="when speed is usually more important than quality printing"
text4="monochrome laser printer when only a greyscale"
text4="Note that the resulting image may not exactly match the requested"
text5="mode and size. To make sure that the image is not larger"
text6="given size, use the thumbnail method instead."
output_file=open("Final.txt","a")
output_file.write(text1)
output_file.write(text2)
output_file.write(text3)
output_file.write(text4)
output_file.write(text5)
output_file.write(text6)
output_file.close()
import collections
import itertools
import sys
with open('output\\Final.txt') as f:
for line in f:
if 'used' in line:
print("OPR")
sys.stdout.write(line)
sys.stdout.writelines(itertools.islice(f, 4))
my doubt is i have 3 text files called Finaltxt.1,Finaltxt.2,Finaltxt.3 in the some directory how i do check the "used" word for all three text files and write 3 lines of text which i have done above code