码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-03-07 15:44:35      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:英文   class   print   大写   word   info   tran   style   dict   

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())  

 

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

标签:英文   class   print   大写   word   info   tran   style   dict   

原文地址:https://www.cnblogs.com/nicole-zhang/p/10489839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!