我有一个名为file1的输入文件,其中包含:
Student 0 : Performed well but can do better. [76.50%]
Student 1 : Brilliant performance. [98.50%]
在这个特定的文件中,我只想删除%部分,以便它生成如下输出:
Student 0 : Performed well but can do better.
Student 1 : Brilliant performance.
我试着这样做:
with open('file1', 'r') as infile, open('file2', 'w') as outfile:
temp = infile.read().replace("[[0-9]+]", "").replace("%","")
outfile.write(temp)
但这只是删除%符号并将输出作为:
Student 0 : Performed well but can do better. [76.50]
Student 1 : Brilliant performance. [98.50]
您仍然需要正则表达式:
相关问题 更多 >
编程相关推荐