登录
首页精彩阅读Python批量修改文本文件内容的方法
Python批量修改文本文件内容的方法
2018-07-18
收藏

Python批量修改文本文件内容的方法

Python批量替换文件内容,支持嵌套文件夹    
import os
path="./"
for root,dirs,files in os.walk(path):
for name in files:
#print name
if name.endswith(".html"):
#print root,dirs,name
filename=root+"/"+name
f=open(filename,"r")
filecontent=""
line=f.readline()
while line:
l=line.replace(":/arcgis_js_api","/arcgisapi")
filecontent=filecontent+l
line=f.readline()
f.close()
f=file(filename,"w")
f.writelines(filecontent)
f.close()
关于本文给大家介绍的Python批量修改文本文件内容的方法

数据分析咨询请扫描二维码

客服在线
立即咨询