eg:
properties=open("text.txt",'r+')
lines=properties.readlines()
d=""
forlineinlines:
c=line.replace("my name is abc","my name is efg")
d+=c
properties.seek(0)#不要让python记住执行到这里,从文件头还始
properties.truncate()#清空文件
properties.write(d)
properties.close()
网友评论