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