艺赛旗 RPA10.0全新首发免费下载 点击下载
www.i-search.com.cn/index.html?from=line1
安装
pip install pypinyin
使用代码
import pypinyin
不带声调的(style=pypinyin.NORMAL)
def pinyin(word):
s = ‘’
for i in pypinyin.pinyin(word, style=pypinyin.NORMAL):
s += ‘’.join(i)
return s
带声调的(默认)
def yinjie(word):
s = ‘’
# heteronym=True开启多音字
for i in pypinyin.pinyin(word, heteronym=True):
s = s + ‘’.join(i) + " "
return s
if name == “main”:
print(pinyin(“自强不息”))
print(yinjie(“厚德载物”))
运行结果:
ziqiangbuxi
hòu dé zài wù