【发布时间】:2019-04-19 10:32:56
【问题描述】:
with open ('npt.mdp','r+') as npt:
if 'Water_and_ions' in npt.read():
print(" I am replacing water and Ions...with only Water")
s=npt.read()
s= s.replace('Protein_BSS Water_and_ions', 'Protein_BSS Water')
with open ('npt.mdp',"w") as f:
f.write(s)
我要替换的文本没有被替换。为什么?
【问题讨论】:
标签: python python-3.x file-handling