我对这个答案的评论。
我写了 /t/min.py 它将在 python3 中运行良好但在 python2 中运行良好(字典理解在 python3 中有效)
/t/min.py 的内容
#!/usr/bin/python3
# -*- py-python-command: "/usr/bin/python3"; -*-
a = {i:i**2 for i in range(10)}
print(a)
请注意,shebang 表示 python3 和文件局部变量 py-python-command 也。
我还编写了 /t/min-py.el 以确保使用 python-mode.el(版本 5.1.0)而不是 python.el。
/t/min-py.el 的内容
(add-to-list 'load-path "~/m/em/lisp/")
(autoload 'python-mode "python-mode" "Python Mode." t)
;; (setq py-python-command "python3")
注意最后一行被注释掉了。
我使用以下命令启动 emacs:
emacs -Q -l /t/min-py.el /t/min.py &
现在 emacs 以我的备用 dotmacs /t/min-py.el 启动,它打开 /t/min.py。
当我按 Cc Cc 将缓冲区发送到 python 时,它说“for”部分是错误的,这表明正在使用 python2 而不是 python3。当我按抄送!启动python解释器,它说python 2.5已启动。
我什至可以将 /t/min.py 的第二行更改为:
# -*- py-python-command: "chunkybacon"; -*-
再做一次这个实验,emacs 仍然使用 python2。
如果 /t/min-py.el 的最后一行没有被注释掉,那么 Cc Cc 和 Cc !两者都使用python3。