美文网首页
linux下PYthon tab补全

linux下PYthon tab补全

作者: 指间_流年 | 来源:发表于2017-10-24 16:43 被阅读0次

一、查看Python安装路径

[root@controller ~]# python

Python 2.7.5 (default, Nov 20 2015, 02:00:19)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> sys.path

['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']

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

[root@controller ~]# cd /usr/lib64/python2.7/

[root@controller python2.7]# vim 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

三、避免进入python之后,不用每次都导入tab模块

###进入家目录,编写 .bashrc文件在最后添加下面一行,保存退出###

[root@controller ~]#vim .bashrc

export PYTHONSTARTUP=/usr/lib64/python2.7/tab.py

###家目录.bashrc文件只有用户登录时才会加载生效,需要进行下面的操作来生效###

[root@controller ~]#source .bashrc

OK,那么现在我们就可以不用每次进行python之后进行import tab 动作来使tab键补全功能生效了。

相关文章

网友评论

      本文标题:linux下PYthon tab补全

      本文链接:https://www.haomeiwen.com/subject/slhxpxtx.html