python tab键自动补全没反应_CentOS下为python命令行添加Tab键自动补全功能

难道python命令就真的没办法使用Tab键的自动补全功能么? 当然不是了,我们依然可以使用。只不过需要自己动手配置一下。

操作系统环境:CentOS release 6.4 x86_32  软件版本:Python 2.6.6 下面我们具体了解配置方法: 1、编写一个Tab键自动补全功能的脚本。 新手会说不会写怎么办? 搜索引擎可以帮助你,关键字(python tab键 自动补全)

1、编写一个Tab键自动补全功能的脚本。新手会说不会写怎么办?搜索引擎可以帮助你,关键字(python tab键 自动补全)vim startup.py

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

2、查看python默认的模块存放路径。

默认的是这个:/usr/lib/python2.6

3、拷贝功能脚本到默认模块存放路径。cp startup.py /usr/lib/python2.6

4、使用方法:

输入的时候调用下startup即可

import startup 如下图:

你可能感兴趣的:(python,tab键自动补全没反应)