pip install pypinyin / pip3 install pypinyin
>>> from pypinyin import pinyin, lazy_pinyin,Style
>>> import pypinyin
>>> pinyin(u'单个', heteronym=True)
[['dān', 'chán', 'shàn'], ['gè', 'gàn', 'gě']]
>>> pinyin(u'单个',heteronym=False)
[['dān'], ['gè']]
>>> pinyin(u'单个')
[['dān'], ['gè']]
>>> lazy_pinyin(u'单个')
['dan', 'ge']
from pypinyin import pinyin, Style
(1)Style.TONE3音调显示在末尾
>>> pinyin('单个',style=Style.TONE3)
[['dan1'], ['ge4']]#数字为音调
>>> pinyin('单个',style=Style.TONE3,heteronym=True)
[['dan1', 'chan2', 'shan4'], ['ge4', 'gan4', 'ge3']]#数字为音调
(2) Style.TONE2音调显示在韵母
>>> pinyin('单个',style=Style.TONE2,heteronym=True)
[['da1n', 'cha2n', 'sha4n'], ['ge4', 'ga4n', 'ge3']]#数字为音调
(3)Style.TONE音调为手写格式
>>> pinyin('单个',style=Style.TONE)
[['dān'], ['gè']]
>>> pinyin('单个',style=Style.TONE,heteronym=True)
[['dān', 'chán', 'shàn'], ['gè', 'gàn', 'gě']]
(4)pypinyin.NORMAL不显示音调
>>> pinyin(u'单个', heteronym=True,style=pypinyin.NORMAL)
[['dan', 'chan', 'shan'], ['ge', 'gan']]
>>> pinyin(u'单个', style=pypinyin.NORMAL)
[['dan'], ['ge']]