Add interactive mode tab autocomplete and command history functions for Python

Source: Internet
Author: User

the next article
new Python environment variable configuration file:
under the host user directory
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 a environment variable to point
# to it: ' Export pythonstartup=~/.pystartup ' in bash.


Import atexit
Import OS
Import ReadLine
Import Rlcompleter
readline.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


To set the python environment variable:
permanent entry into force:
echo "Export Pythonstartup=~/.pystartup" >>/etc/profile
Source/etc/profile

Verification:
[email protected] ~]# python27
Python 2.7.9 (default, June, 16:05:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "Help", "copyright", "credits" or "license" for more information.
>>> e
elif Else Enumerate (eval_r (except exec execfile (exit ) (
>>> e

This article is from the "Jinchuang" blog, make sure to keep this source http://jinchuang.blog.51cto.com/8690689/1844413

Add interactive mode tab autocomplete and command history functions for Python

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.