file_data = ''
    str1 = '1'
    str2 = '2'
    with open(loginfofile, 'r+') as f:       #打开文件,r+模式,读取
        for line in f:
            if str1 in line:
                line = line.replace(str1, 'n')        #将str替换为n

            if str2 in line:
                line2 = line.replace(str2, 'n')
                file_data += line2
    with open(logproducefile, 'w') as f:            #以写入方式打开文件w
        f.write(file_data)

 

相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2021-10-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-14
  • 2021-08-18
  • 2022-12-23
  • 2021-10-28
  • 2022-03-04
  • 2022-12-23
相关资源
相似解决方案