我將terminal.app設置爲接受utf-8並在bash中可以輸入unicode字符並複製並粘貼它們,但是如果我啓動python殼我不能,如果我嘗試解碼的unicode我得到的錯誤:無法在os上解碼utf-8字符串x terminal.app
>>> wtf = u'\xe4\xf6\xfc'.decode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
>>> wtf = u'\xe4\xf6\xfc'.decode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
任何人都知道我做錯了嗎?
[這](http://stackoverflow.com/問題/ 368805/python-unicodedecodeerror-am-i-misunderstanding-encode/370199#370199)在有關編碼/解碼的相關問題中回答可能會有所幫助。 – tzot 2009-04-27 10:12:00