python注释文件内容
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
posted on 2019-11-12 22:11 gentleman_hai 阅读(414) 评论(0) 收藏 举报
浙公网安备 33010602011771号