The interactive command line for Python can be configured through a startup file.
When Python starts, it looks for the environment variable Pythonstartup and executes the program code in the file specified in the variable. The specified file name and address can be arbitrary. Pressing the TAB key automatically complements the content and command history. This is an effective enhancement to the command line, which is implemented based on the ReadLine module (which requires a ReadLine library-assisted implementation).
Here's a simple example of a startup script file that adds a button auto-complete content and history command functionality to the Python command line.
[Python@python ~]$ Cat. Pythonstartupimport readlineimport rlcompleterimport atexitimport os#tab Completionreadline.parse_and_bind (' Tab:complete ') #history filehistfile = Os.path.join (os.environ[' HOME '], '. Pythonhistory ') Try: readline.read_history_file (histfile) except IOError: passatexit.register ( Readline.write_history_file,histfile) del Os,histfile,readline,rlcompleter
Setting environment variables
[Python@python ~]$ Cat. Bash_profile|grep Pythonexport Pythonstartup=/home/python/.pythonstartup
Verify tab completion and historical command viewing.
[Python@python ~]$ Pythonpython 2.7.5 (default, Oct 6, 10:45:13) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on Linux2type "Help", "copyright", "credits" or "license" for more information.>>> import md5>>> md5.md5.__class__ ( c0/>md5.__getattribute__ (md5.__reduce__ (md5.__subclasshook__ (md5.__delattr__ (md5.__hash__ (md5._ _reduce_ex__ ( md5.blocksizemd5.__dict__ md5.__init__ ( md5.__repr__ ( md5.digest_sizemd5.__doc__ md5.__name__ md5.__setattr__ ( md5.md5 (md5.__file__ md5.__new__ ( md5.__sizeof__ ( Md5.new (md5.__format__ ( md5.__package__ md5.__str__ ( md5.warnings>>> Import os>> > Import MD5
Note: If the make is present:
Python build finished, but the necessary bits-to-build these modules were not found:_tkinter gdbm readline Sunaudiodev
If this is ignored, import ReadLine will make an error. Indicates no module specified!
Here is the missing specified package:
Redhat: readline-devel.xxx.rpm
The problem can be resolved by recompiling the installation.