Automatic configuration of the tab key in Python
When a beginner learns Python, how can he not have the tab key completion function? I feel like it is a nightmare. For cainiao like us, I just got started with python and didn't know everything, fortunately, with the guidance of our predecessors, I learned about it and recorded it. I haven't learned this function yet! Get it!
- 1. First, check the python installation path.
[root@localhost ~]# pythonPython 2.6.6 (r266:84292, Oct 12 2012, 14:23:48) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.path['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/python2.6/site-packages']
- Switch the directory to the python installation directory and write the tab key completion module.
[root@localhost ~]# cd /usr/lib64/python2.6[root@localhost python2.6]# vim tab.py#!/usr/bin/env python # python startup file import sysimport readlineimport rlcompleterimport atexitimport 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: passatexit.register(readline.write_history_file, histfile)del os, histfile, readline, rlcompleter
- After writing, you can import the tab key to python to complete the task.
root@localhost python2.6]# pythonPython 2.6.6 (r266:84292, Oct 12 2012, 14:23:48) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import tab>>> sys.sys.__class__( sys.__reduce_ex__( sys.builtin_module_names sys.exitfunc( sys.maxsize sys.setprofile(sys.__delattr__( sys.__repr__( sys.byteorder sys.flags sys.maxunicode sys.setrecursionlimit(sys.__dict__ sys.__setattr__( sys.call_tracing( sys.float_info sys.meta_path sys.settrace(sys.__displayhook__( sys.__sizeof__( sys.callstats( sys.getcheckinterval( sys.modules sys.stderrsys.__doc__ sys.__stderr__ sys.copyright sys.getdefaultencoding( sys.path sys.stdinsys.__excepthook__( sys.__stdin__ sys.displayhook( sys.getdlopenflags( sys.path_hooks sys.stdoutsys.__format__( sys.__stdout__ sys.dont_write_bytecode sys.getfilesystemencoding( sys.path_importer_cache sys.subversionsys.__getattribute__( sys.__str__( sys.exc_clear( sys.getprofile( sys.platform sys.versionsys.__hash__( sys.__subclasshook__( sys.exc_info( sys.getrecursionlimit( sys.prefix sys.version_infosys.__init__( sys._clear_type_cache( sys.exc_type sys.getrefcount( sys.ps1 sys.warnoptionssys.__name__ sys._current_frames( sys.excepthook( sys.getsizeof( sys.ps2 sys.__new__( sys._getframe( sys.exec_prefix sys.gettrace( sys.py3kwarning sys.__package__ sys.api_version sys.executable sys.hexversion sys.setcheckinterval( sys.__reduce__( sys.argv sys.exit( sys.maxint sys.setdlopenflags(
- In order to enter the python directory, you do not need to import it every time. In this case, go to the home directory, write the. bashrc file, add the following line at the end, save and exit.
[root@localhost ~]# cd ~[root@localhost ~]# vim .bashrcexport PYTHONSTARTUP=/usr/lib64/python2.6/tab.py
- The Home Directory. bashrc file takes effect only when the user logs on. You need to perform the following operations to take effect.
[root@localhost ~]# source .bashrc
OK, so now we don't need to execute the import tab action every time after python to make the tab key completion function take effect.
Install Python3.4 on CentOS source code
Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]
Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]
Obtain Linux information using a Python script
Build a desktop algorithm transaction research environment using Python in Ubuntu
A Brief History of Python Development
Python details: click here
For Python, click here.
This article permanently updates the link address: