Skip to main content

汉语拼音转换工具.

Project description

Build Coverage PyPI version

将汉语转为拼音。可以用于汉字注音、排序、检索。

基于 hotoo/pinyin 开发。

特性

  • 根据词组智能匹配最正确的拼音。

  • 支持多音字。

  • 简单的繁体支持。

  • 支持多种不同拼音风格。

安装

$ pip install pypinyin

文档

详细文档请访问:http://pypinyin.rtfd.io/

使用示例

>>> from pypinyin import pinyin, lazy_pinyin
>>> import pypinyin
>>> pinyin(u'中心')
[[u'zh\u014dng'], [u'x\u012bn']]
>>> pinyin(u'中心', heteronym=True)  # 启用多音字模式
[[u'zh\u014dng', u'zh\xf2ng'], [u'x\u012bn']]
>>> pinyin(u'中心', style=pypinyin.FIRST_LETTER)  # 设置拼音风格
[['z'], ['x']]
>>> pinyin('中心', style=pypinyin.TONE2, heteronym=True)
[['zho1ng', 'zho4ng'], ['xi1n']]
>>> lazy_pinyin(u'中心')  # 不考虑多音字的情况
['zhong', 'xin']

命令行工具:

$ pypinyin 音乐
yīn yuè
$ pypinyin -h

FAQ

为什么没有 y, w, yu 几个声母?

声母风格(INITIALS)下,“雨”、“我”、“圆”等汉字返回空字符串,因为根据 《汉语拼音方案》 , y,w,ü (yu) 都不是声母,在某些特定韵母无声母时,才加上 y 或 w,而 ü 也有其特定规则。 —— @hotoo

如果你觉得这个给你带来了麻烦,那么也请小心一些无声母的汉字(如“啊”、“饿”、“按”、“昂”等)。 这时候你也许需要的是首字母风格(FIRST_LETTER)。 —— @hotoo

参考: hotoo/pinyin#57, #22, #27, #44

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pypinyin-0.13.0.tar.gz (733.1 kB view details)

Uploaded Source

Built Distribution

pypinyin-0.13.0-py2.py3-none-any.whl (741.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pypinyin-0.13.0.tar.gz.

File metadata

  • Download URL: pypinyin-0.13.0.tar.gz
  • Upload date:
  • Size: 733.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pypinyin-0.13.0.tar.gz
Algorithm Hash digest
SHA256 fcd9661881c1b3770db2956ea781fcd62f375cf39d37024c6578a6c392aeb761
MD5 77f2a0bda7ea656a08c7daa4a3c7c63b
BLAKE2b-256 3c5572d88d6fc77bc6963930583656ae15067fac1580fce18224c10c6194e1a2

See more details on using hashes here.

File details

Details for the file pypinyin-0.13.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pypinyin-0.13.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c3f853d5d6b817e5e38a2e115a14da0eb468cc88418f09ae08a649690ef40893
MD5 4abbb22ea8030f22395b638be689f227
BLAKE2b-256 3528cb6ee802789faba001e0dffbac6df299e058c7a9a1d8dba7e47d4e28019a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page