📜  python 替换文件中的字符串 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:22.579000             🧑  作者: Mango

代码示例3
#!/usr/bin/env python3
import fileinput

with fileinput.FileInput(filename, inplace=True, backup='.bak') as file:
    for line in file:
        print(line.replace(text_to_search, replacement_text), end='')