脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python批量修改文本文件内容的方法

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

2020-08-21 10:47yijia Python

这篇文章主要介绍了Python批量修改文本文件内容的方法的相关资料,需要的朋友可以参考下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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批量修改文本文件内容的方法,大家都看懂了,如果大家有疑问欢迎给我留言,小编会及时给大家回复的!

延伸 · 阅读

精彩推荐