def __upgrade_replace_text__(path, text, replace): with fileinput.FileInput(path, inplace=True, backup=".bak") as _file: for line in _file: print(line.replace(text, replace), end='')