码迷,mamicode.com
首页 > 其他好文 > 详细

读写文件

时间:2018-06-28 00:00:26      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:file   def   readlines   write   ESS   txt   adl   tps   写文件   

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()

读写文件

标签:file   def   readlines   write   ESS   txt   adl   tps   写文件   

原文地址:https://www.cnblogs.com/xiaoxiaocaicai/p/9236469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!