This article mainly introduces relevant information on how to batch modify the contents of text files in Python. Friends who need it can refer to
Python batch replaces file contents and supports nested folders
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()
Everyone understands the method of batch modifying text file contents in Python introduced in this article. If you have any questions, please leave me a message and the editor will promptly Reply to everyone!
For more detailed information on how to batch modify the contents of text files in Python, please pay attention to the PHP Chinese website for related articles!