Python command line completion

Source: Internet
Author: User
Tags readline

Python command line completion


As you know, when you enter a command in the command line interface, you can use the TAB key to fill in the command, which is easy to set up without wasting a long time on the input command. Recently started contacting Python and found that using the TAB key under the Python command line is not a complete command. Can we set the pattern to complete the command line? The answer is yes.


We can import modules under the Python command line

Import ReadLine, Rlcompleter; Readline.parse_and_bind ("Tab:complete")


With this setting, we can use the TAB key to complete the completion. But the downside to this approach is that you shut down the interface, and when you re-enter the Python interface, you have to re-enter the command, which is a hassle.

So, we can also write a configuration file that will permanently write this parameter

Create a file: ~/.pythonstartup.py

Vim ~/.pythonstartup.pyimport ReadLine, Rlcompleter; Readline.parse_and_bind ("Tab:complete")


Add an environment variable inside the ~/.BASHRC

Vim ~/.bashrcexport pythonstartup=~/.pythonstartup.py


Finally again source ~/.BASHRC


In this way, each time you start Python, you can automatically complete the command

This article is from the "xhk__" blog, please be sure to keep this source http://xhk777.blog.51cto.com/13405744/1980841

Python command line completion

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.