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())
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/10489839.html