读写文件

import re

def readfile(path):
f=open(path)
lines=f.readlines()
f.close()

return lines

def writefile(path,lines):
f=open(path,'w')
f.writelines(lines)
f.close()

def processContents(lines):
for i in range(len(lines)):
if(lines[i]):
lines[i] = re.sub('http:','https:',lines[i])

return lines

def processFile():

paths=['E:\\tt.txt']
for path in paths:
lines=readfile(path)
processContents(lines)
writefile(path,lines)

processFile()

posted on 2018-06-27 23:02  DaMengZhang  阅读(98)  评论(0编辑  收藏  举报