650) this.width=650; "src=" http://s11.sinaimg.cn/mw690/001KTqJHzy6XX4k5wFk5a "alt=" 001ktqjhzy6xx4k5wfk5a "/>
#-*-Coding:utf-8-*-
FILE = input ("Please enter file path:")
Word1 = input ("Please enter the word to be replaced:")
Word2 = input ("Please enter a new word:")
F=open (file, "r+")
Aaa=f.read ()
Count = 0
Def BBB ():
Global Count
For each in AAA:
if each = = Word1:
Count=count+1
Print ("Total" "+str (count) +" "+str (word1) +" "")
BBB ()
#红色这一段其实是最最容易蒙圈的地方 #
Print ("Are you sure you want to replace All" "+str (word1) +" with "" "+str (WORD2) +"? ")
K=input ("yes/no": ")
Aaa=aaa.replace (WORD1,WORD2)
While True:
If k== "yes" or k== "yes":
Print (AAA)
Break
Else
Print ("Action canceled!")
Break
This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1728957
A "Find and replace" function from a text file