6754 发表于 2017-9-20 10:20:05

centos中配置python的tab键自动补全功能

centos中配置python的tab键自动补全功能一、首先打开python,观察python的安装路径
# python
Python 3.6.2 (default, Aug 14 2017, 22:12:34)
on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/root/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages']
>>>

二、退出python、进入python目录
# cd /usr/local/lib/python3.6/

三、新建tab.py文件,并且输入配置内容
# 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:
【更新地址】http://doublelinux.blog.51cto.com/12300166/1966544
    pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter

四、验证
# python
Python 3.6.2 (default, Aug 14 2017, 22:12:34)
on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a
abs(   all(   and      any(   as       ascii(   assert   
>>> b
bin(      bool(       break       bytearray(bytes(      
>>> c
callable(   chr(          class         classmethod(compile(      complex(      continue   
>>>


页: [1]
查看完整版本: centos中配置python的tab键自动补全功能