【发布时间】:2010-10-21 23:28:15
【问题描述】:
我将 terminal.app 设置为接受 utf-8 并且在 bash 中我可以输入 unicode 字符,复制并粘贴它们,但是如果我启动 python shell 我不能,如果我尝试解码 unicode 我会得到错误:
>>> 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)
有人知道我做错了什么吗?
【问题讨论】:
-
This 回答有关编码/解码的相关问题可能会有所帮助。
标签: python macos unicode terminal