file1 = open(I, 'r') Icontent = file1.read() editedData = Icontent.replace(S, T) file2 = open(O, 'w') file2.write(editedData) file1.close() file2.close()