如何编写逐行读取文本文件并删除所有 'the' 单词并将其写入另一个文件的程序
How to write a program that reads the text file line by line and remove all the 'the' words and write it to another file
这个程序怎么做?我用了很多方法,但不是 work.This 是代码。
def remove():
f1=open("Sample.txt",'r')
x=f1.read()
x.split()
f2=open("Result.txt",'w')
for i in x:
if 'the' not in i:
f2.write(i)
print(f2) # This is to view the result.
f2.close()
f1.close()
f2=open("Result.txt",'r')
f2.read()
remove()
我不是 100% 确定这就是您想要的,但可能是这样的:
text = open('Sample.txt', 'r').read()
text = text.replace('the', '')
with open('Result.txt', 'w') as f2:
f2.write(text)
这个程序怎么做?我用了很多方法,但不是 work.This 是代码。
def remove():
f1=open("Sample.txt",'r')
x=f1.read()
x.split()
f2=open("Result.txt",'w')
for i in x:
if 'the' not in i:
f2.write(i)
print(f2) # This is to view the result.
f2.close()
f1.close()
f2=open("Result.txt",'r')
f2.read()
remove()
我不是 100% 确定这就是您想要的,但可能是这样的:
text = open('Sample.txt', 'r').read()
text = text.replace('the', '')
with open('Result.txt', 'w') as f2:
f2.write(text)