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

高洛峰
Release: 2017-03-06 13:40:12
Original
2003 people have browsed it

这篇文章主要介绍了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()
Copy after login

关于本文给大家介绍的Python批量修改文本文件内容的方法,大家都看懂了,如果大家有疑问欢迎给我留言,小编会及时给大家回复的!

更多Python批量修改文本文件内容的方法详解相关文章请关注PHP中文网!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!