学习Python的时候,如何没有tab键补全功能,我感觉那将是一个噩梦,对于我们这种菜鸟来说,刚接触python,对一切都不了解,还好有前辈们的指导,学习一下,并记录下来,还没有学习这个功能小伙伴们!
环境:
[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[root@localhost ~]#
具体过程:
[root@localhost site-packages]# python #进入python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys #导入sys模块
>>> sys.path #确认系统默认撸觉
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']
>>> exit()
[root@localhost site-packages]# pwd #进入要放入tab.py文件的目录(上面的路径,随便放一个),我防止如下目录:
/usr/lib64/python2.7/site-packages
###########################################################
[root@localhost site-packages]# cat tab.py
#!/usr/bin/python # python tab complete 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
###########################################################
[root@localhost site-packages]# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab #使用前先导入tab模块
>>> import sys #下面就可以使用tab键了
>>> sys.
sys.__class__( sys.__sizeof__( sys.copyright sys.getfilesystemencoding( sys.prefix
sys.__delattr__( sys.__stderr__ sys.displayhook( sys.getprofile( sys.ps1
sys.__dict__ sys.__stdin__ sys.dont_write_bytecode sys.getrecursionlimit( sys.ps2
sys.__displayhook__( sys.__stdout__ sys.exc_clear( sys.getrefcount( sys.py3kwarning
sys.__doc__ sys.__str__( sys.exc_info( sys.getsizeof( sys.pydebug
sys.__excepthook__( sys.__subclasshook__( sys.exc_type sys.gettrace( sys.setcheckinterval(
sys.__format__( sys._clear_type_cache( sys.excepthook( sys.hexversion sys.setdlopenflags(
sys.__getattribute__( sys._current_frames( sys.exec_prefix sys.long_info sys.setprofile(
sys.__hash__( sys._debugmallocstats( sys.executable sys.maxint sys.setrecursionlimit(
sys.__init__( sys._getframe( sys.exit( sys.maxsize sys.settrace(
sys.__name__ sys._mercurial sys.exitfunc( sys.maxunicode sys.stderr
sys.__new__( sys.api_version sys.flags sys.meta_path sys.stdin
sys.__package__ sys.argv sys.float_info sys.modules sys.stdout
sys.__reduce__( sys.builtin_module_names sys.float_repr_style sys.path sys.subversion
sys.__reduce_ex__( sys.byteorder sys.getcheckinterval( sys.path_hooks sys.version
sys.__repr__( sys.call_tracing( sys.getdefaultencoding( sys.path_importer_cache sys.version_info
sys.__setattr__( sys.callstats( sys.getdlopenflags( sys.platform sys.warnoptions
>>> sys.