python汉字转拼音代码_Python 汉字转换拼音代码
# -*-coding:utf-8-*-
# 返回漢字的拼音
def Return_pinyin(word):
global reslist
for line in reslist:
if (word==line[0]+line[1]) or (word==line[2]+line
[3]):
str = line
break
# 取①和②之間的內容
s = str.find(u'①')+4
e = str.find(u'②')+3
return str[s:e]
def GetPy(word):
#首先裝載資源文件
i=0
allstr = ''
while i
if ord(word[i])>127:
if allstr:
allstr += Return_pinyin(word[i]+word[i+1])
else:
allstr = Return_pinyin(word[i]+word[i+1])
i +=2
else:
if allstr:
allstr += word[i]
else:
allstr = word[i]
i +=1
return allstr
if __name__=='__main__':
f = open('wbtext1.txt','r')
reslist = f.readlines()
f.close()
word = raw_input(u'請輸入漢字: ')
print GetPy(word).lower()
總結
以上是生活随笔為你收集整理的python汉字转拼音代码_Python 汉字转换拼音代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 技术交底软件_【干货分享】软件类产品如何
- 下一篇: 【LeetCode笔记】112 113