Python批量替换文件内容,支持嵌套文件夹
import ospath="./"for root,dirs,files in os.walk(path):for name in files:#print nameif name.endswith(".html"):#print root,dirs,name filename=root+"/"+namef=open(filename,"r")filecontent=""line=f.readline() while line:l=line.replace(":/arcgis_js_api","/arcgisapi")filecontent=filecontent+lline=f.readline()f.close()f=file(filename,"w")f.writelines(filecontent)f.close()
关于本文给大家介绍的Python批量修改文本文件内容的方法,大家都看懂了,如果大家有疑问欢迎给我留言,小编会及时给大家回复的!