python自动化测试——中文转拼音,转英文

import pinyin.cedict

# 转拼音
# nǐhǎo
print(pinyin.get('你好'))  

# ni hao
print(pinyin.get('你好', format="strip", delimiter=" "))  

# ni3hao3
print(pinyin.get('你好', format="numerical"))  

# 获取首字母 n h
print(pinyin.get_initial('你好'))  

# 转英文
# ['you (informal, as opposed to courteous 您[nin2])']
print(pinyin.cedict.translate_word(''))  

# ['Hello!', 'Hi!', 'How are you?']
print(pinyin.cedict.translate_word('你好'))

# [['你', ['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']]]
print(list(pinyin.cedict.all_phrase_translations('你好'))) 

#获取首字母并转为大写 Z
print(pinyin.get_initial("张一")[0].upper())  

 

posted @ 2019-03-07 15:18  OTAKU_nicole  阅读(3266)  评论(0编辑  收藏  举报