Linux下面python命令补齐模块

在Linux下添加tab命令补齐功能

1.新建一个tab.py文件存放在python能默认找到的lib库里面,本次存放在"/usr/lib64/python3.4"目录下面

2.代码:

#!/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

  

3. 测试

# python
Python 3.4.10 (default, Apr  8 2019, 02:17:36) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab
>>> import sys
>>> sys.a
sys.abiflags     sys.api_version  sys.argv         
>>> sys.a
sys.abiflags     sys.api_version  sys.argv               

>>> sys.argv
sys.argv
>>> sys.argv

4. 加载后tab可以补全命令了。

posted @ 2019-06-10 16:05  PlayOn  阅读(592)  评论(0编辑  收藏  举报