【发布时间】:2011-02-12 16:38:32
【问题描述】:
如果我尝试粘贴 unicode 字符,例如中间点:
·
在我的 python 解释器中它什么也不做。我在 Mac OS X 上使用 Terminal.app,当我只是在 bash 中时,我没有问题:
:~$ ·
但在解释器中:
:~$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
^^ 我什么也没得到,它只是忽略了我刚刚粘贴的字符。如果我使用中间点 '\xc2\xb7' 的转义 \xNN\xNN 表示,并尝试转换为 unicode,尝试显示点会导致解释器抛出错误:
>>> unicode('\xc2\xb7')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)
我在 sitecustomize.py 中设置了 'utf-8' 作为我的默认编码:
>>> sys.getdefaultencoding()
'utf-8'
什么给了?这不是终端。不是 Python,我做错了什么?!
此问题与此question 无关,因为该个人能够将 unicode 粘贴到他的终端中。
【问题讨论】:
-
我也有同样的问题,但是默认编码是ascii(不知道为什么):((
标签: python unicode macos terminal