with open('outputFile', 'r+') as f: text = f.read() f.seek(0) f.truncate() f.write(text.replace('(comma)', ' , '))