【问题标题】:default tab completion like ipython in python console默认选项卡完成,如 python 控制台中的 ipython
【发布时间】:2013-07-11 04:16:07
【问题描述】:

我知道我可以用这个:

import rlcompleter, readline
readline.parse_and_bind('tab: complete')

在我的 python 解释器中启用 ipython 样式的选项卡完成。

我怎样才能让它在启动时默认运行,每当我启动 python 时?

【问题讨论】:

    标签: python


    【解决方案1】:

    将其放入文件.pythonrc(您可以通过环境变量PYTHONSTARTUP控制该文件的名称)。阅读更多关于here

    PYTHONSTARTUP
    If this is the name of a readable file, the Python commands 
    in that file are executed before the first prompt is displayed
    in interactive mode. The file is executed in the same namespace
    where interactive commands are executed so that objects defined
    or imported in it can be used without qualification in the interactive
    session. You can also change the prompts sys.ps1 and sys.ps2 in this file.
    

    另见:

    【讨论】:

    • 您链接了有关 Python 2.7 与 3.2 的问题 - 这是否意味着您必须在 OP 的代码中为 2 与 3 做一些不同的事情?
    • 啊,可能不是这样...readline 在 OS X 上是用libedit 实现的。你必须根据this answer 使用"bind ^I rl_complete"
    • 我似乎没有 .pythonrc 文件。是否有推荐的标准位置将其放在 ubuntu 机器上? Just export PYTHONSTARTUP=$HOME/.pythonrc 就像您提到的其他答案一样?
    猜你喜欢
    • 2015-12-09
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 2013-02-13
    • 2022-11-30
    • 1970-01-01
    相关资源
    最近更新 更多