加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 20:43:28 所属栏目:Python 来源:网络整理
导读:Python批量替换文件内容,支持嵌套文件夹 import ospath="./"for root,dirs,files in os.walk(path):for name in files:#print nameif name.endswith(".html"):#print root,name filename=root+"/"+namef=open(filename,"r")filecontent=""line=f.readline()

Python批量替换文件内容,支持嵌套文件夹

import os
path="./"
for root,dirs,files in os.walk(path):
for name in files:
#print name
if name.endswith(".html"):
#print root,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批量修改文本文件内容的方法,大家都看懂了,如果大家有疑问欢迎给我留言,小编会及时给大家回复的!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读