我已經閱讀了不止一次的「unicode on python 2.7 how-to」並且徹底地瀏覽了這個論壇,但沒有發現和嘗試讓我的程序工作。raw_inputting Unicode字符串
它應該將dictionary.com條目轉換成例句集合以及單詞 - 發音對。然而,它從一開始就失敗了:IPA(即unicode)字符在輸入後立即轉換爲亂碼。
# -*- coding: utf-8 -*-
""" HERE'S HOW A TYPICAL DICTIONARY.COM ENTRY LOOKS LIKE
white·wash
/ˈʰwaɪtˌwɒʃ, -ˌwɔʃ, ˈwaɪt-/ Show Spelled
noun
1.
a composition, as of lime and water or of whiting, size, and water, used for whitening walls, woodwork, etc.
2.
anything, as deceptive words or actions, used to cover up or gloss over faults, errors, or wrongdoings, or absolve a wrongdoer from blame.
3.
Sports Informal. a defeat in which the loser fails to score.
verb (used with object)
4.
to whiten with whitewash.
5.
to cover up or gloss over the faults or errors of; absolve from blame.
6.
Sports Informal. to defeat by keeping the opponent from scoring: The home team whitewashed the visitors eight to nothing.
"""
def wdefinp(): #word definition input
wdef=u''
emptylines=0
print '\nREADY\n\n'
while True:
cinp=raw_input() #current input line
if cinp=='':
emptylines += 1
if emptylines >= 3: #breaking out by 3xEnter
wdef=wdef[:-2]
return wdef
else:
emptylines = 0
wdef=wdef + '\n' + cinp
return wdef
wdef=wdefinp()
print wdef.decode('utf-8')
這產生了: white·洗 /EE°waÉŞtËŚwÉ'Ę,-ËŚwÉ」 E,ËwaÉŞt-/顯示拼寫 ...
任何幫助將是讚賞。
適合我,從eclipse,python 2.7和你的測試數據運行 – Vorsprung 2013-03-10 19:11:59