python 汉字转拼音
首先是安装第三方库:
$ pip install pinyin
使用的话:
>>> import pinyin >>> print pinyin.get('你 好') nǐ hǎo >>> print pinyin.get('你好', format="strip", delimiter=" ") ni hao >>> print pinyin.get('你好', format="numerical") ni3hao3 >>> print pinyin.get_initial('你好') n h
而且还提供了汉字转英语的方法:Prototype Chinese->English
>>> import pinyin.cedict >>> pinyin.cedict.translate_word('你') ['you (informal, as opposed to courteous 您[nin2])'] >>> pinyin.cedict.translate_word('你好') ['Hello!', 'Hi!', 'How are you?'] >>> list(pinyin.cedict.all_phrase_translations('你好')) [['你', ['you (informal, as opposed to courteous 您[nin2])']], ['你好', ['Hello!', 'Hi!', 'How are you?']], ['好', ['to be fond of', 'to have a tendency to', 'to be prone to']]]
AIEarth是一个由众多领域内专家博主共同打造的学术平台,旨在建设一个拥抱智慧未来的学术殿堂!【平台地址:https://devpress.csdn.net/aiearth】 很高兴认识你!加入我们共同进步!