安裝好python環境後,經過執行/usr/local/python/bin/python2.7能夠直接進入python環境,進行相關的編輯:python
[root@agent ~]# /usr/local/python/bin/python2.7 Python 2.7.10 (default, Jul 10 2015, 15:41:26) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 100 + 200 300 >>> print "hello,world" hello,world
可是,此時,新建一個列表list1,若是想查看其相關的屬性,使用Tab鍵沒有任何反應linux
>>> list1=['a','b',1,3] >>> list1.
已經習慣了使用linux Tab來補全命令,在python裏面卻不能使用Tab,這種感受真不爽,從網上搜了一下,如何使用python tab自動補全的腳本bash
1.進入用戶的宿主目錄(家目錄),建立一個名爲.startup文件,具體內容以下:app
import sys import readline import rlcompleter import atexit import os readline.parse_and_bind('tab: complete') 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.在/root目錄的.bashrc文件添加環境變量,執行如下命令便可:
python2.7
echo "export PYTHONSTARTUP=~/.pythonstartup" >> ~/.bashrc
3.退出SSH從新登錄即,進入python後便可用tab補全ssh
[root@agent ~]# /usr/local/python/bin/python2.7 Python 2.7.10 (default, Jul 10 2015, 15:41:26) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> list1=['a','b',1,3] >>> list1. list1.__add__( list1.__ge__( list1.__iter__( list1.__repr__( list1.append( list1.__class__( list1.__getattribute__( list1.__le__( list1.__reversed__( list1.count( list1.__contains__( list1.__getitem__( list1.__len__( list1.__rmul__( list1.extend( list1.__delattr__( list1.__getslice__( list1.__lt__( list1.__setattr__( list1.index( list1.__delitem__( list1.__gt__( list1.__mul__( list1.__setitem__( list1.insert( list1.__delslice__( list1.__hash__ list1.__ne__( list1.__setslice__( list1.pop( list1.__doc__ list1.__iadd__( list1.__new__( list1.__sizeof__( list1.remove( list1.__eq__( list1.__imul__( list1.__reduce__( list1.__str__( list1.reverse( list1.__format__( list1.__init__( list1.__reduce_ex__( list1.__subclasshook__( list1.sort(