python 将汉字转换拼音


废话少说直接上代码

a='百度;www.baidu.com'
from xpinyin import Pinyin


# 实例拼音转换对象
p = Pinyin()
# 进行拼音转换
ret = p.get_pinyin(u"百度;www.baidu.com", tone_marks='marks')
ret1 = p.get_pinyin(u"汉语拼音转换", tone_marks='numbers')
print(ret+'\n'+ret1)