实现多个字符串的批量转换
import re
import os
s = os.sep
root = "G:\daizhuan"
for i in os.listdir(root):
if os.path.isfile(os.path.join(root,i)):
print ("i")
filePath = os.path.join(root,i)
a= open(filePath,'r') #打开所有文件
str = a.read()
str = str.replace("<div", "<view") # 将字符串里前面全部替换为后面
str = str.replace("<p","<view")
str = str.replace("div>", "view>")
str = str.replace("p>", "view>")
print (os.path.join(root,i))
print (str)
b = open(filePath,'w')
b.write(str) #再写入
b.close() #关闭文件