python实际工作中,做一些小工具,很方便。最近在做一个格式转换工具时候,用到了替换文件中特定字符串的

功能。当初没直接想出来,就在网上查了一下,做个记录,方便后续使用。

  

# -*- coding: utf-8 -*-
#把文件内容替换
#把file3.txt 的 hello 替换为 good,并保存到file3Back.txt
import re

fp3=open("audio.txt","rb")
fp4=open("file4.txt","wb")

for s in fp3.readlines():#先读出来   
    fp4.write(s.replace("\n",",")) #替换 并写入
          
fp3.close()
fp4.close()

  

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-02-19
  • 2021-09-17
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案