码迷,mamicode.com
首页 > 编程语言 > 详细

python tab complete

时间:2019-10-30 13:34:39      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:write   style   exit   nova   import   environ   col   test   too   

一、查询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

标签:write   style   exit   nova   import   environ   col   test   too   

原文地址:https://www.cnblogs.com/cjyp/p/11764075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!