Skip to main content

Rewrite lxneng's xpinyin by cython

Project description

Rewrite lxneng’s xpinyin by cython since by commit 3599c101f659bb7cfbc7e5c5c5684206e4fab5f9 <>.

The interfaces are completely consistent and can be seamlessly switched with xpinyin;


pip install cpinyin


Replace xpinyin.Pinyin with cpinyin.Pinyin

>>> import cpinyin
>>> cpinyin.install()
>>> from xpinyin import Pinyin
>>> p = Pinyin()
>>> p.get_pinyin(u"上海")

Consistent with the xpinyin Api.

>>> from cpinyin import Pinyin
>>> p = Pinyin()
>>> # default splitter is `-`
>>> p.get_pinyin(u"上海")
>>> # show tone marks
>>> p.get_pinyin(u"上海", tone_marks=u'marks')
>>> p.get_pinyin(u"上海", tone_marks=u'numbers')
>>> 'shang4-hai3'
>>> # remove splitter
>>> p.get_pinyin(u"上海", u'')
>>> # set splitter as whitespace
>>> p.get_pinyin(u"上海", u' ')
'shang hai'
>>> p.get_initial(u"上")
>>> p.get_initials(u"上海")
>>> p.get_initials(u"上海", u'')
>>> p.get_initials(u"上海", u' ')
'S H'

Please enter Chinese characters encoding by utf8.

>>> wordvalue = '中国'
>>> wordvalue= unicode(wordvalue, 'utf-8')
>>> s = p.get_initials(wordvalue, u'').lower()

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpinyin-0.1.2.tar.gz (128.6 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page