Python adds tab Auto Completion and command history functions.

Source: Internet
Author: User

1. Create a new Python environment variable configuration file:

vim ~/.pystartup# add auto-completion and a stored history file  Of commands to your python# interactive interpreter. requires python  2.0+, readline. autocomplete is# bound to the esc key by  default  (You can change it - see readline docs). ## store  the file in ~/.pystartup, and set an environment variable  to point# to it:   "Export pythonstartup=~/.pystartup"  in bash.import  atexitimport osimport readlineimport rlcompleterreadline.parse_and_bind (' tab:  Complete ') Historypath = os.path.expanduser ("~/.pyhistory") def save_history (historyPath= Historypath):     import readline    readline.write_history_file ( Historypath) if os.path.exists (hiStorypath):     readline.read_history_file (Historypath) atexit.register (save_history) del  os, atexit, readline, rlcompleter, save_history, historypath

2. Set the python environment variable:

Immediate effect, restart failure: Export Pythonstartup=~/.pystartup

Permanent entry: Echo "Export Pythonstartup=~/.pystartup" >>/etc/profile


Note: The default complement is ESC.

Readline.parse_and_bind (' tab:complete ') This command is used to set tab completion.

~/.pyhistory preserves the history of the operation commands in the Python interactive interface.



This article is from the "you insist on _it blog" blog, please be sure to keep this source http://fdgui.blog.51cto.com/3484207/1563434

Python adds tab Auto Completion and command history functions.

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.