【发布时间】:2014-07-28 18:48:48
【问题描述】:
有没有办法为 python 中的import 语句启用制表符补全?
例子:
$ cd test/
$ ls
mytest.py
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import my<TAB>
>>> import shuti<TAB>
mytest 或任何其他模块(例如shutil)没有制表符补全。我用 python 3.4 得到了相同的结果。我使用的是 Ubuntu 14.04,我的 shell 是 bash。
请注意,制表符补全在其他 Python 解释器上下文中也有效,例如补全函数和标识符名称。
我的 .pystartup 配置如下:
import atexit
import os
import readline
import rlcompleter
readline.parse_and_bind("tab: complete")
historyPath = os.path.expanduser("~/.pyhistory")
def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)
if os.path.exists(historyPath):
readline.read_history_file(historyPath)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
【问题讨论】:
-
我建议通过
pip install bpython尝试bpython,然后启动bpython 作为解释器包装器。它提供选项卡补全、代码提示和代码着色。 -
你应该试试IPython shell。
标签: python tab-completion