xpinyin

translate chinese hanzi to pinyin by python

Github星跟蹤圖

xpinyin

.. image:: https://img.shields.io/travis/lxneng/xpinyin.svg
:target: https://travis-ci.org/lxneng/xpinyin

.. image:: https://img.shields.io/pypi/v/xpinyin.svg
:target: https://pypi.python.org/pypi/xpinyin/

.. image:: https://img.shields.io/pypi/dm/xpinyin.svg
:target: https://pypi.python.org/pypi/xpinyin/

translate chinese hanzi to pinyin by python, inspired by flyerhzm’s
chinese\_pinyin_ gem

Install

::

pip install xpinyin

Usage

::

>>> from xpinyin import Pinyin
>>> p = Pinyin()
>>> # default splitter is `-`
>>> p.get_pinyin(u"上海")
'shang-hai'
>>> # show tone marks
>>> p.get_pinyin(u"上海", tone_marks='marks')
'shàng-hǎi'
>>> p.get_pinyin(u"上海", tone_marks='numbers')
>>> 'shang4-hai3'
>>> # 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'

如果方法中传入变量,那么直接加前缀是不可以了。而是要将变量转为utf-8编码:
>>> wordvalue = '中国'
>>> wordvalue= unicode(wordvalue,'utf-8')
>>> s = p.get_initials(wordvalue, u'').lower()
'zg'

请输入utf8编码汉字

.. _chinese_pinyin: https://github.com/flyerhzm/chinese_pinyin

主要指標

概覽
名稱與所有者lxneng/xpinyin
主編程語言Python
編程語言Python (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2010-05-20 13:28:54
推送於2025-06-02 04:33:20
最后一次提交2025-06-02 12:33:15
發布數0
用户参与
星數831
關注者數42
派生數176
提交數129
已啟用問題?
問題數41
打開的問題數9
拉請求數19
打開的拉請求數0
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?