替换txt文件字符
import os
文件路径
file_path = ‘1.txt’
file_path2 = ‘2.txt’
读取文件内容
with open(file_path, ‘r’) as file:
content = file.read()
替换文本中的多个不同字符串
content = content.replace(‘替换√2’, ‘替换为@Outlook.com’)
… 可以继续替换更多字符串
写回新的文件内
with open(file_path2, ‘w’) as file:
file.write(content)
原文作者: J时游
原文链接: https://feichang99.github.io/or/fd4adf21.html
版权声明: 转载请注明出处(必须保留作者署名及链接)