相关疑难解决方法(0)

使Emacs在Python交互模式下使用UTF-8

当我从Mac OS的Terminal.app启动Python时,python将编码识别为UTF-8:

$ python3.0
Python 3.0.1 (r301:69556, May 18 2009, 16:44:01) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
Run Code Online (Sandbox Code Playgroud)

这对python2.5也是一样的.

但在Emacs中,编码是US-ASCII.

Python 3.0.1 (r301:69556, May 18 2009, 16:44:01) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'US-ASCII'
Run Code Online (Sandbox Code Playgroud)

如何使Emacs与Python通信以便sys.stdout知道使用UTF-8?


编辑:由于我没有编辑接受的答案的代表,这正是在Aquaemacs 1.6,Mac OS 10.5.6上对我有用的.

在python-mode-hook中,我添加了该行

(setenv "LANG" "en_GB.UTF-8")
Run Code Online (Sandbox Code Playgroud)

显然,Mac OS需要"UTF-8",而dfa说Ubuntu需要"UTF8".

另外,我必须通过执行Cx RET p然后输入两次"utf-8"来设置输入/输出编码.我应该知道如何永久地设置它. …

python emacs terminal encoding utf-8

7
推荐指数
1
解决办法
2239
查看次数

标签 统计

emacs ×1

encoding ×1

python ×1

terminal ×1

utf-8 ×1