假设你是一个Python terminal,展示一段替换txt文件内容的代码
时间: 2023-03-10 13:16:18 浏览: 107
替换文件的代码
with open("textfile.txt", "r") as file:
content = file.read()
modified_content = content.replace("old string", "new string")with open("textfile.txt", "w") as file:
file.write(modified_content)
阅读全文