python tab complete

Posted csuyangpeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python tab complete相关的知识,希望对你有一定的参考价值。

一、查询python安装路径,一般默认是/usr/bin/

moonx@moonx:/usr/download/test/mypython$ python

Python 2.7.12 (default, Oct 8 2019, 14:14:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
[‘‘, ‘/opt/stack/keystone‘, ‘/opt/stack/glance‘, ‘/opt/stack/neutron‘, ‘/opt/stack/nova‘, ‘/opt/stack/horizon‘, ‘/opt/ros/kinetic/lib/python2.7/dist-packages‘, ‘/usr/lib/python2.7‘, ‘/usr/lib/python2.7/plat-x86_64-linux-gnu‘, ‘/usr/lib/python2.7/lib-tk‘, ‘/usr/lib/python2.7/lib-old‘, ‘/usr/lib/python2.7/lib-dynload‘, ‘/home/moonx/.local/lib/python2.7/site-packages‘, ‘/usr/local/lib/python2.7/dist-packages‘, ‘/usr/lib/python2.7/dist-packages‘, ‘/usr/lib/python2.7/dist-packages/PILcompat‘, ‘/usr/lib/python2.7/dist-packages/gtk-2.0‘, ‘/usr/lib/python2.7/dist-packages/wx-3.0-gtk2‘]
>>>

二、切换到python的安装目录下,编辑tab键补全模块

  moonx@moonx:/usr/download/test/mypython$ cd /usr/local/lib/python2.7/
  moonx@moonx:/usr/local/lib/python2.7$ pwd
  /usr/local/lib/python2.7
  moonx@moonx:/usr/local/lib/python2.7$ vi tab.py

#!/usr/bin/env python
# python startup file 
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion 
readline.parse_and_bind(‘tab: complete‘)
# history file 
histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘)
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter

三、修改~/.bashrc

moonx@moonx:/usr/local/lib/python2.7$ echo "export PYTHONSTARTUP=/usr/local/lib/python2.7/tab.py" >> ~/.bashrc
moonx@moonx:/usr/local/lib/python2.7$ source ~/.bashrc

四、进入python测试,可正常使用tab补全功能了

moonx@moonx:/usr/download/test/mypython$ python
Python 2.7.12 (default, Oct 8 2019, 14:14:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import simple_package
>>> simple_package

以上是关于python tab complete的主要内容,如果未能解决你的问题,请参考以下文章

python 交互界面tab补全

python代码自动补全

python tab补全

在 Powershell 中建立参数后使用 Tab Complete

Python基础 (tab自动补全)

Python tab补全命令