python中文(汉字)转拼音

1.python库pypinyin

可以使用 pip 进行安装:

$ pip install pypinyin

easy_install 安装:

$ easy_install pypinyin

源码安装:

$ python setup.py install

pypinyin0.28.0文档:
http://pypinyin.mozillazg.com/zh_CN/master/index.html



2.python库xpinyin

安装: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'

3.python库pinyin

    原文作者:Roninwz
    原文地址: https://blog.csdn.net/qq_35038153/article/details/78771251
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞