手机
当前位置:查字典教程网 >脚本专栏 >python >Python批量修改文本文件内容的方法
Python批量修改文本文件内容的方法
摘要:Python批量替换文件内容,支持嵌套文件夹importospath="./"forroot,dirs,filesinos.walk(pat...

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批量修改文本文件内容的方法,大家都看懂了,如果大家有疑问欢迎给我留言,小编会及时给大家回复的!

【Python批量修改文本文件内容的方法】相关文章:

Python获取远程文件大小的函数代码分享

python操作xml文件详细介绍

python练习程序批量修改文件名

python批量下载图片的三种方法

python和shell变量互相传递的几种方法

python生成器的使用方法

Python操作列表的常用方法分享

Python删除指定目录下过期文件的2个脚本分享

python 测试实现方法

Python open读写文件实现脚本

精品推荐
分类导航