Sep-04-2020, 12:02 AM
Hi,
I hope I'm not overstaying my welcome here.
I'm trying to redirect a print statement to a file with no luck.
I have no errors, just nothing is printed to my file.
code:
I hope I'm not overstaying my welcome here.
I'm trying to redirect a print statement to a file with no luck.
I have no errors, just nothing is printed to my file.
code:
from itertools import islice
myfile = 'C:///LogFile.txt'
outfile = open('C://OUTPUT.txt','w')
index = 0
with open(myfile, "r") as f:
for line in f:
index += 1
if "FIND" in line:
f.seek(0)
print("".join(islice(f, index - 5, index + 4)))
outfile.write(''.join(islice(f, index - 5, index + 4)))
outfile.close()
