如把test.txt文件的 所有 AAA 字符串 替换成 aaaaa
with open('test.txt','+r') as f:
t = f.read()
t = t.replace('AAA', 'aaaaaa')
#读写偏移位置移到最开始处
f.seek(0, 0)
f.write(t)
如把test.txt文件的 所有 AAA 字符串 替换成 aaaaa
with open('test.txt','+r') as f:
t = f.read()
t = t.replace('AAA', 'aaaaaa')
#读写偏移位置移到最开始处
f.seek(0, 0)
f.write(t)