当前位置: 代码迷 >> 综合 >> python 替换文件中的字符串
  详细解决方案

python 替换文件中的字符串

热度:84   发布时间:2024-02-10 05:57:24.0

如把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)

 

 

  相关解决方案