- """
- python正则替换语言文件=号后的内容合并.py
- 这个版本使用正则匹配替换
- 使用cn文件中已有的内容,正则替换en文件内容输出到out.txt
- out.txt保持了en文件的顺序
- """
- import re
- with open("zh_CN.lang",encoding="utf-8") as f:
- zh=f.read()
- rec=re.compile("(.+)=(.*)\\n")
- zht=re.findall(rec,zh)
- with open("en_US.lang",encoding="utf-8") as f:
- en=f.read()
- for e,c in zht:
- rec=re.compile("(%s)=(.*)\\n" %e)
- en=re.sub(rec,r"\\1=%s\\n" %c,en)
- with open("out.txt","w+",encoding="utf-8") as f:
- f.write(en)
- f.close()
- #该片段来自于http://www.codesnippet.cn/detail/0912201514206.html
来源: http://www.codesnippet.cn/detail/0912201514206.html