Python Kanji Conversion Phonetic Code

Source: Internet
Author: User

Python Kanji Conversion Phonetic Code

#-*-coding:utf-8-*-
# return pinyin of Chinese characters
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
# take the content between ① and ②
s = str.find (U ' ① ') +4
E = str.find (U ' ② ') +3
return Str[s:e]

def getpy (word):
#首先装载资源文件
I=0
Allstr = ' '
While I<len (word):
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 ' Please enter Chinese characters: ')
Print getpy (word). Lower ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.