1 Star 0 Fork 0

NatureLiu/python-pinyin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gen_pinyin_dict.py 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
mozillazg 提交于 2019-02-24 09:54 . fix flake8 lint on python 3.7
# -*- coding: utf-8 -*-
import sys
def main(in_fp, out_fp):
out_fp.write('''# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# Warning: Auto-generated file, don't edit.
pinyin_dict = {
''')
for line in in_fp.readlines():
line = line.strip()
if line.startswith('#') or not line:
continue
else:
# line is U+4E2D: zhōng,zhòng # 中
# raw_line U+4E2D: zhōng,zhòng
raw_line = line.split('#')[0].strip()
# 0x4E2D: zhōng,zhòng
new_line = raw_line.replace('U+', '0x')
# 0x4E2D: 'zhōng,zhòng
new_line = new_line.replace(': ', ": '")
# 0x4E2D: 'zhōng,zhòng'\n
new_line = " {new_line}',\n".format(new_line=new_line)
out_fp.write(new_line)
out_fp.write('}\n')
if __name__ == '__main__':
if len(sys.argv) == 1:
print('python gen_pinyin_dict.py INPUT OUTPUT')
sys.exit(1)
in_f = sys.argv[1]
out_f = sys.argv[2]
with open(in_f) as in_fp, open(out_f, 'w') as out_fp:
main(in_fp, out_fp)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ulipcb/python-pinyin.git
git@gitee.com:ulipcb/python-pinyin.git
ulipcb
python-pinyin
python-pinyin
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385