with open("testfisier", "r+") as file:
for line in file:
for index in range(len(line)):
if line[index] is "a":
replace_file = line[index].replace("a", "")
# Write the changes.
file.write(replace_file)
或:
with open("testfisier", "r+") as f:
f.write(f.read().replace("a", ""))
你可以试试这个:
没有任何更改,因为您没有将其写回文件
或:
尝试使用regexp替换。例如,假设您已读入该字符串并将其命名为\u字符串
import re re.sub('a','',a_string,'')
这将是许多可能的解决办法之一希望这有帮助
相关问题 更多 >
编程相关推荐