您的位置:首页 > 编程语言 > Python开发

Python脚本04 —— 模板中字体统一改成font1、font2、font3、font4、font5、font6

2015-09-22 12:07 585 查看
#模板中字体统一改成font1、font2、font3、font4、font5、font6
# coding=utf8
import os,sys
def replace(f):
if not os.path.exists(f): # 看一下这个文件是否存在
exit(-1)                             #,不存在就退出

lines = open(f).readlines()  #打开文件,读入每一行

newFile = os.path.join(newDir,f)
fp = open(newFile,'w')  #打开你要写得文件pp2.txt
for s in lines:
fp.write( s.replace('DFPHaiBaoW12','font1').replace('FZYBKSJW--GB1-0','font2').replace('HYh3gj','font3').replace('jdabiaosong','font4').replace('GBHerSin-Medium','font5').replace('NotoSansHans-Light','font6'))   # replace是替换,write是写入
fp.close()  # 关闭文件

def createNewDir():
isExist = os.path.exists(newDir)
if not isExist:
print "dir not exist. create dir: " + newDir
os.mkdir(newDir)
else:
print "dir exist: " + newDir

dir = sys.path[0]
print dir
newDir = sys.path[0] + "/new/"
createNewDir()
for f in os.listdir(dir):
if (os.path.isfile(f)) and os.path.splitext(f)[1] == '.json':
replace(f)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  脚本