|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
报错:
- def file_replace(file_name,rep_word,_new_word):
- f_read = open(file_name)
- content = []
- count = 0
- for eachline in f_read:
- if rep_word in eachline:
- count = eachline.count(rep_word)
- eachline = eachline.replace(rep_word,new_word)
- content.append(eachline)
- decide = input('确认替换吗?【YES/NO】:')
- if decide in ['YES','Yes','yes']:
- f_write = open(file_name,'w')
- f_write.writeline(content)
- f_write.close()
- f_read.close()
- file_name = input('请输入文件名:')
- rep_word = input('请输入需要替换的单词或字符:')
- new_word = input('请输入新的单词或字符:')
- file_replace(file_name,rep_word,new_word)
复制代码
详情: Message='_io.TextIOWrapper' object has no attribute 'writeline'
Source=B:\Python38\Python code\PythonApplication1\PythonApplication1.py
StackTrace:
File "B:\Python38\Python code\PythonApplication1\PythonApplication1.py", line 17, in file_replace
f_write.writeline(content)
File "B:\Python38\Python code\PythonApplication1\PythonApplication1.py", line 26, in <module>
file_replace(file_name,rep_word,new_word)
|
|