# -*- coding: UTF-8 -*-
file = input("请输入文件路径:")
word1 = input("请输入要替换的词:")
word2 = input("请输入新的词:")
f=open(file,"r+")
AAA=f.read()
count = 0
def BBB():
global count
for each in AAA:
if each == word1:
count=count+1
print("一共有【"+str(count)+"】处要找的【"+str(word1)+"】")
BBB()
#红色这一段其实是最最容易蒙圈的地方#
print("您确定要把所有的【"+str(word1)+"】替换为【"+str(word2)+"】吗?")
K=input("【YES/NO】:")
AAA=AAA.replace(word1,word2)
while True:
if K=="YES" or K=="yes":
print(AAA)
break
else:
print("操作取消!")
break
转载于:https://blog.51cto.com/chenx1242/1728957