我已经不止一次地阅读了“unicode on python 2.7 how-to”并彻底浏览了这个论坛,但我没有找到并尝试过让我的程序正常工作。
它应该将 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·wash /Ë�Ę°waÉŞtËŚwÉ'Ę�, -ËŚwÉ”Ę�, Ë�waÉŞt-/ Show Spelled ...
任何帮助将不胜感激。