python把中文文档变为拼音的方法
程序员文章站
2022-04-22 09:18:43
pip install xpinyin
这是个中文转拼音的pakage
>>> from xpinyin import Pinyin
>>&...
pip install xpinyin
这是个中文转拼音的pakage
>>> from xpinyin import Pinyin >>> p = Pinyin() >>> # default splitter is `-` >>> p.get_pinyin(u"上海") 'shang-hai' >>> # show tone marks >>> p.get_pinyin(u"上海", show_tone_marks=True) 'shàng-hǎi' >>> # remove splitter >>> p.get_pinyin(u"上海", '') 'shanghai' >>> # set splitter as whitespace >>> p.get_pinyin(u"上海", ' ') 'shang hai' >>> p.get_initial(u"上") 'S' >>> p.get_initials(u"上海") 'S-H' >>> p.get_initials(u"上海", u'') 'SH' >>> p.get_initials(u"上海", u' ') 'S H'
上一篇: mariadb集群与nginx负载均衡配置--centos7版本
下一篇: linux安装JDK