1、怎么注释文件文件

文件内容

1.1.1.1 good idea
192.168.1.214  xxx.com
192.168.201.48 xxx.com
192.168.201.48 xxx.com
python代码

#/bin/env python
#coding:utf-8
import re

w_str=''
with open('./file','r+') as fobj:
    for line in fobj.readlines():
        line = re.sub('^','#',line)
        w_str+=line
        print w_str

with open('./file','wb') as fobj:
    fobj.write(w_str)
输出结果:

#1.1.1.1 good idea
#192.168.1.214  xxx.com
#192.168.201.48 xxx.com
#192.168.201.48 xxx.com

  

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2021-08-28
  • 2021-09-17
  • 2022-12-23
  • 2021-08-07
  • 2021-07-26
  • 2021-06-10
猜你喜欢
  • 2021-09-06
  • 2022-01-01
  • 2021-07-01
  • 2021-12-16
  • 2021-12-05
  • 2022-02-08
相关资源
相似解决方案