|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def replace(name=r"C:\Users\Administrator\Desktop\新建文本文档.txt",word,new):
- f=open(name)
- content=[]
- count=0
- for each_line in f:
- if word in each_line:
- count+=each_line.count(word)
- each_line=each_line.replace(word,new)
- content.append(each_line)
- choice=input("%s的个数为%d,你确定将%s替换为【%s】吗?【yes/no】"%(word,count,word,new))
- if choice in "yesYesYESyEsysEYEsySEYsE":
- f=open(name,"w")
- f.writelines(content)
- f.close()
- name=input("请输入你需要修改的文件名")
- word=input("请输入需要修改的文字")
- new=input("请输入更改的文字")
- if name=='':
- replace(word=word,new=new)
- else:
- replace(name,word,new)
复制代码
这个哪错了,如果去掉默认参数,输入name是能完全实现的
|
|