Python命令添加Tab键自动补全

环境介绍OS:RHEL 5.5Python版本:2.7.6在使用linux命令的时候我们习惯使用下Tab键,在python下我们也可以实现类似的功能。类似Linix shell的TAB功能,Python也可以实现的!具体实现过程如下:1.编写python脚本$ cat tab_enable.py#!/usr/bin/python# python startup fileimport sysimport readlineimport rlcompleterimport atexitimport os# tab completionreadline.parse_and_bind(‘tab: complete’)# history filehistfile = os.path.join(os.environ[‘HOME’], ‘.pythonhistory’)try: readline.read_history_file(histfile)except IOError: passatexit.register(readline.write_history_file, histfile)del os, histfile, readline, rlcompleter2.调用脚本将脚本放置在python默认模块,路径下,,/usr/local/python27/lib/python2.7/tab_enable.py开始调用>>> import tab_enable>>> import os>>> os.<Tab>备注:1.安装readline时报错gcc: readline/libreadline.a: No such file or directory,解决办法[root@ readline-6.2.4.1]#yum -y install readline-devel[root@ readline-6.2.4.1]#yum -y install patch[root@ readline-6.2.4.1]# python setup.py install

没有人会帮你一辈子,所以你要奋斗一生。

Python命令添加Tab键自动补全

相关文章:

你感兴趣的文章:

标签云: