【发布时间】:2016-04-17 12:42:01
【问题描述】:
我在我的一些 Python 脚本中使用以下技巧进入交互式 Python REPL 会话:
import code; code.InteractiveConsole(locals=globals()).interact()
这通常在工作中的各种 RHEL 机器上运行良好,但在我的笔记本电脑(OS X 10.11.4)上,它似乎在没有 readline 支持的情况下启动 REPL。你可以看到我得到了^[[A^C 垃圾字符。
My-MBP:~ complex$ cat repl.py
a = 'alpha'
import code; code.InteractiveConsole(locals=globals()).interact()
b = 'beta'
My-MBP:~ complex$ python repl.py
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> a
'alpha'
>>> ^[[A^C
如果我直接调用python,REPL 中的向上箭头命令历史记录可以正常工作。
我尝试检查globals() 以寻找一些线索,但在每种情况下它们似乎都是相同的。关于如何解决此问题或在哪里查看的任何想法?
编辑:并显示正确的行为:
My-MBP:~ complex$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 'a'
'a'
>>> 'a'
【问题讨论】:
标签: python macos readline read-eval-print-loop