今天开始学习Python,必须配置tab键补全功能
1.首先我们需要查看python的安装路径
[root@abc ~]# python Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/usr/lib/python2.6/site-packages/cloud_init-0.7.6-py2.6.egg', '/usr/lib/python2.6/site-packages/jsonpatch-1.13-py2.6.egg', '/usr/lib/python2.6/site-packages/requests-2.9.1-py2.6.egg', '/usr/lib/python2.6/site-packages/argparse-1.4.0-py2.6.egg', '/usr/lib/python2.6/site-packages/Jinja2-2.8-py2.6.egg', '/usr/lib/python2.6/site-packages/jsonpointer-1.10-py2.6.egg', '/usr/lib/python2.6/site-packages/six-1.10.0-py2.6.egg', '/usr/lib/python2.6/site-packages/AliyunUtil-0.0.1-py2.6.egg', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
2.切换目录到python的安装目录下,进行tab键补全模块的编写
[root@localhost ~]# cd /usr/lib64/python2.6 [root@localhost python2.6]# 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
注意:一定要安装上边代码的严格缩进来做,防止不生效。
进入家目录,编写 .bashrc文件在最后添加下面一行,保存退出。
[root@localhost ~]# cd ~ [root@localhost ~]# vim .bashrc export PYTHONSTARTUP=/usr/lib64/python2.6/tab.py
家目录.bashrc文件只有用户登录时才会加载生效,需要进行下面的操作来生效
[root@localhost ~]# source .bashrc
那么现在就可以使用tab键补全功能了