python文件操作--字符串替换

如把test.txt文件的 所有 AAA 字符串 替换成 aaaaa

1 with open('test.txt','+r') as f:
2     t = f.read()
3     t = t.replace('AAA', 'aaaaaa')
4    #读写偏移位置移到最开始处 
5     f.seek(0, 0)    
6     f.write(t)
原文地址:https://www.cnblogs.com/linkenpark/p/5167867.html