Add idle and historical functionality to the Python _python

Source: Internet
Author: User
Tags readline

Many times, we use Python without having to write a program, some uncomplicated tasks, and I prefer to enter a few lines of code in IDLE (that is, interactive cue mode). However, in this mode to edit the code, there are not convenient places, the most important thing is, can not use the tab automatic completion, can not remember the last input command (no way, who let us in the shell accustomed to it).
At this point, we can start the script directly using Python to solve this problem.

The program that starts the script is very simple, here is not a lot of instructions, just give the code:

Import readline
import rlcompleter
import atexit
import OS
# tab AutoComplete
Readline.parse_and _bind (' Tab:complete ')
# history file
histfile = os.path.join (os.environ[' home '], '. Pythonhistory ')
try:
readline.read_history_file (histfile)
except IOError:
pass
atexit.register (readline.write_ History_file, Histfile)

When we're done, we'll save it as. Pythonstartup, store it in our own directory (for example,/home/yurii), and then point the Pythonstartup variable to the address you just put. The easiest way to do this is to add one line to the BASHRC:

Copy Code code as follows:

Export Pythonstartup=/home/yurii/.pythonstartup

In this way, not only increased the tab automatically complement the full function, and restart the idle, through the key, but also turn to the last input command, very convenient.

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.