import os
def updateFile(file,old_str,new_str):
"""
替换文件中的字符串
:param file:文件名
:param old_str:旧字符串
:param new_str:新字符串
:return:
"""
file_data = ""
with open(file, "r") as f:
for line in f:
line = line.replace(old_str,new_str)
file_data += line
with open(file,"w") as f:
f.write(file_data)
Python修改txt文件内容,Python替换txt文件关键字
于 2020-05-28 15:18:00 首次发布