在python3中(使用run-python命令调用emacs ):
>>> sys.version
sys.version
'3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
>>> sys.getdefaultencoding()
sys.getdefaultencoding()
'utf-8'
>>> data
data
'sp\xe4m'
>>> print(data)
print(data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 2: ordinal not in range(128)在终端中:
~$python3
Python 3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> data='sp\xe4m'
>>> sys.getdefaultencoding()
'utf-8'
>>> data
'späm'
>>> print(data)
späm有没有人知道为什么Python的unicode字符串可以在终端中工作,而不能在emacs中工作
( emacs版本信息:GNU Emacs 24.2.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2012-08-27 on bob.porkrind.org)
发布于 2013-12-19 16:41:11
键入以下语句,python即可正常工作
export PYTHONIOENCODING='utf-8'https://stackoverflow.com/questions/14172576
复制相似问题