安装好python环境后,通过执行/usr/local/python/bin/python2.7可以直接进入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键没有任何反应
>>> list1=['a','b',1,3] >>> list1.
已经习惯了使用linux Tab来补全命令,在python里面却不能使用Tab,这种感觉真不爽,从网上搜了一下,如何使用python tab自动补全的脚本
1.进入用户的宿主目录(家目录),创建一个名为.startup文件,具体内容如下:
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文件添加环境变量,执行以下命令即可:
echo "export PYTHONSTARTUP=~/.pythonstartup" >> ~/.bashrc
3.退出SSH重新登陆即,进入python后即可用tab补全
[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(