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

 

相关文章:

  • 2021-10-17
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2022-01-26
  • 2021-12-24
  • 2022-12-23
相关资源
相似解决方案