python汉字转拼音

from pypinyin import lazy_pinyin

from xpinyin import Pinyin

# import sys

# reload(sys)

# sys.setdefaultencoding('utf-8')

a= u'抖音'

# 得到全拼

s = ''.join(lazy_pinyin(a))

print s # douyin

# 得到首字母

change_p = Pinyin()

name = u'{0}'.format(a)

S = change_p.get_initials(name, u'')

print S # DY

 

你可能感兴趣的:(python汉字转拼音)