Apr-18-2019, 09:14 PM
You could have one loop do both the reading and writing; this is probably better anyway if that's all you are doing.
infile = open("C:\\Users\\John\Desktop\\StuffIn.txt", "r") outfile = open("C:\\Users\\John\Desktop\\StuffOut.txt", "w") for line in infile: if stringToMatch in line: #write it to the output file outfile.write(line) infile.close() outfile.close()