python实现tab键自动补全

[root@M1-Server ~]# python -V

Python 2.6.6

 

#脚本

[root@M1-Server py]# cat 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

 

#导入

[root@M1-Server py]# python

Python 2.6.6 (r266:84292, Jun 18 2012, 14:18:47)

[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import tab

>>> import sys

>>> sys.

sys.__class__(              sys.__str__(                sys.exitfunc(               sys.path

sys.__delattr__(            sys.__subclasshook__(       sys.flags                   sys.path_hooks

sys.__dict__                sys._clear_type_cache(      sys.float_info              sys.path_importer_cache

sys.__displayhook__(        sys._current_frames(        sys.getcheckinterval(       sys.platform

sys.__doc__                 sys._getframe(              sys.getdefaultencoding(     sys.prefix

sys.__excepthook__(         sys.api_version             sys.getdlopenflags(         sys.ps1

sys.__format__(             sys.argv                    sys.getfilesystemencoding(  sys.ps2

sys.__getattribute__(       sys.builtin_module_names    sys.getprofile(             sys.py3kwarning

sys.__hash__(               sys.byteorder               sys.getrecursionlimit(      sys.setcheckinterval(

sys.__init__(               sys.call_tracing(           sys.getrefcount(            sys.setdlopenflags(

sys.__name__                sys.callstats(              sys.getsizeof(              sys.setprofile(

sys.__new__(                sys.copyright               sys.gettrace(               sys.setrecursionlimit(

sys.__package__             sys.displayhook(            sys.hexversion              sys.settrace(

sys.__reduce__(             sys.dont_write_bytecode     sys.last_traceback          sys.stderr

sys.__reduce_ex__(          sys.exc_clear(              sys.last_type(              sys.stdin

sys.__repr__(               sys.exc_info(               sys.last_value              sys.stdout

sys.__setattr__(            sys.exc_type                sys.maxint                  sys.subversion

sys.__sizeof__(             sys.excepthook(             sys.maxsize                 sys.version

sys.__stderr__              sys.exec_prefix             sys.maxunicode              sys.version_info

sys.__stdin__               sys.executable              sys.meta_path               sys.warnoptions

sys.__stdout__              sys.exit(                   sys.modules      

python实现tab键自动补全
Scroll to top