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.