tab Auto-completion in Python interactive mode

Source: Internet
Author: User

In interactive mode, Python presses the TAB key for the function output of the Time tab key when entering a command, which is inconvenient when writing python.

Write the following code into a file tab.py, and put it under/usr/lib/python2.6/site-packages/.

#!/usr/bin/env pythonimport sysimport readlineimport rlcompleterimport atexitimport osreadline.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)

How to use:

Python enters interactive mode:

>>> import tab>>> import sys>>> sys.sys.__class__ (               sys.api_version              SYS.HEXVERSIONSYS.__DELATTR__ (             sys.argv                     sys.last_type (sys.__dict__                 sys.builtin_module_ names    sys.last_valuesys.__displayhook__ (         sys.byteorder                sys.maxintsys.__doc__                  sys.call_tracING (           sys.maxsizesys.__egginsert              sys.callstats (               sys.maxunicodesys.__excepthook__ (          sys.copyright                sys.meta_pathsys.__format__ (              sys.displayhook (             SYS.MODULESSYS.__GETATTRIBUTE__ (       sys.dont_write_bytecode      sys.pathsys.__hash__ (                sys.exc_clear (               sys.path_hookssys.__init__ (                Sys.exc_info (                sys.path_importer_cachesys.__name__                 sys.exc_type                 sys.platformsys.__new__ (                 sys.excepthook (              sys.prefixsys.__package__              sys.exec_prefix              sys.ps1sys.__plen                   sys.executable              SYS.PS2SYS.__REDUCE__ (              sys.exit (                     Sys.py3kwarningsys.__reduce_ex__ (          sys.exitfunc (                sys.setcheckinterval (Sys.__repr__ (                sys.flags                    sys.setdlopenflags (sys.__setattr__ (             sys.float_info               sys.setprofile (sys.__sizeof__ (  &nbsP;          sys.getcheckinterval (        sys.setrecursionlimit (sys.__stderr__               sys.getdefaultencoding (     sys.settrace (sys.__stdin__                sys.getdlopenflags (          sys.stderrsys.__stdout__               sys.getfilesystemencoding (  sys.stdinsys.__str __ (                 Sys.getprofile (             sys.stdoutsys.__ Subclasshook__ (       sys.getrecursionlimit (       sys.subversionsys._clear_tYpe_cache (      sys.getrefcount (             sys.versionsys._current_frames (         Sys.getsizeof (              sys.version_ Infosys._getframe (               Sys.gettrace (                Sys.warnoptions>>> sys.

This makes it easy to view the function modules.

This article is from the "Operation Utopia" blog, please make sure to keep this source http://joeyang.blog.51cto.com/9092193/1542965

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.