MacOS 上的 Python REPL 选项卡补全
在升级到 lion 之前,我通过终端在 python shell 中完成了 tab 工作。按照这些说明,可以让选项卡完整工作。
自从升级到 Lion 以来,我现在无法在 Python 终端会话中完成选项卡工作。我已经严格按照上面的说明进行操作,但仍然不起作用。
和Lion中的readline模块有什么区别吗?连接到“tab:complete”选项似乎不再起作用。我想知道是终端忽略了 readline,还是 python 本身。
Python 版本:2.7.1
编辑:
按制表符完成,我的意思是我可以执行如下操作:
# django
import MyModel
MyModel.objects.a[TAB] # will complete to all()
Before upgrading to lion, I had tab complete working in a python shell via terminal. Following these instructions, it was possible to have tab complete working.
Since upgrading to Lion, I am now unable to get tab complete working in a terminal session of Python. I've followed the above instructions to the letter, and it still does not work.
Is there a difference with the readline module in Lion? Hooking in to the 'tab:complete' option no longer seems to work. I'm wondering if it is terminal that is ignoring readline, or if it is python itself.
Python version: 2.7.1
Edit:
By tab complete, I mean I could do something like the following:
# django
import MyModel
MyModel.objects.a[TAB] # will complete to all()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple 并未随 OS X 提供 GNU
readline
。它提供 BSD libedit< /a> 其中包括一个 readline 兼容性接口。 Apple 提供的系统 Python 和 python.org 安装程序中的 64 位/32 位 Python 是使用libedit
构建的。问题是libedit
支持的命令与readline
支持的命令完全不同(例如,参见讨论 这里)。传统的仅限 32 位的 python.org 安装程序确实使用 GNUreadline
,就像 MacPorts 等其他一些适用于 OS X 的 Python 第三方发行商一样。很可能您以前使用过这样的 Python,而不是最近的 Apple 的。除了修改 Django 之外,您还有一些选择:您可以安装第三方替换 readline 模块;或者你可以使用 GNU readline 附带的另一个 Python。但是,您不应该在 10.7 上使用 python.org 仅限 32 位的 Python,因为不幸的是,10.7 上的 Xcode 4 不再包含这些 Python 所需的gcc-4.0
和 OS X 10.4u SDK构建并安装带有 C 扩展模块的软件包。将以下内容放入 python 启动文件中将为 libedit 界面和典型的 readline 模块启用制表符补全。有关 python 启动文件的更多信息,请参阅此处
Apple does not ship GNU
readline
with OS X. It does ship BSD libedit which includes areadline
compatibility interface. The system Pythons shipped by Apple and the 64-bit/32-bit Pythons from python.org installers are built withlibedit
. The problem is that the commands supported bylibedit
are completely different from those ofreadline
(see for example the discussion here). The traditional 32-bit-only python.org installers do use GNUreadline
as do some other 3rd-party distributors of Python for OS X, like MacPorts. Chances are that you were previously using such a Python and not a recent Apple one. You do have a few options, besides modifying Django: you can install the third-party replacement readline module; or you can use another Python that comes with GNU readline. However, you should not use the python.org 32-bit-only Pythons on 10.7 because, unfortunately, Xcode 4 on 10.7 no longer includesgcc-4.0
and the OS X 10.4u SDK which those Pythons need to build and install packages with C extension modules.Putting the following in the python startup file will enable tab completion for both the libedit interface and the typical readline module. For more information on the python startup file, see here
由于它使用 libedit/editline,启用自动完成的语法有点不同。
您可以首先通过键入以下内容强制 emacs 绑定(如果我没记错的话,它与 readline 一样):
readline.parse_and_bind("bind -e")
然后您可以添加链接到 TAB 按钮的自动完成功能( man editrc) :
readline.parse_and_bind("bind '\t' rl_complete")
如果你想支持缩进并且有历史记录(在互联网上找到),它应该看起来像这样(除非我犯了错误):
As it uses libedit/editline, the syntax to enable autocompletion is a little bit different.
You can first force emacs bindings (as it is with readline if I'm not wrong) by typing :
readline.parse_and_bind("bind -e")
Then you can add autocompletion linked to your TAB button (man editrc) :
readline.parse_and_bind("bind '\t' rl_complete")
And if you want to support indenting and has a history (found on internet), it should look like that (unless I made a mistake) :