📜  python替换大文件中的部分 - Python代码示例

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

代码示例1
for file in files:
    fname = os.path.join(dir, file)
    inFile = codecs.open(fname, "r", "utf-8")
    outFile = codecs.open(fname + ".new", "w", "utf-8")
    for line in inFile:
        newline = do_replacements_on(line)
        outFile.write(newline)
    inFile.close()
    outFile.close()
    os.rename(fname + ".new", fname)