有没有办法在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
答案 0 :(得分:0)
默认Python的REPL无法做到这一点。现在唯一(实用)的方法是使用IPython(==类固定和使用火箭引擎的REPL):http://ipython.org/