1、批量替换中文
#中文前加u,表示unicode格式
old_str=u"百老汇影城"
name=u"四川太平洋"
print '模板中的字符串:',old_str
def test():
cinemaNamePath='./../dist/pages/login/agreement/agreement.wxml'
fileName = './agreement22222.wxml'
f = file(cinemaNamePath)
output = open(fileName, "w")
for line in f:
# 将line 解码成unicode
line = unicode(line,"utf-8")
#在unicode中找unicode
if line.find(old_str) > 0:
print '找到了 字符串 %s',old_str
line = line.replace(old_str, name)
print '替换后的line = ',line
#把替换后的line,写入到新文件。 将unicode编码成字符串,通过指定的编码(utf-8)
output.write(line.encode('utf-8'))
#print 'line = ',line
f.close()
output.close()
#调用 test方法
test()