16.8. readline — GNU readline interface

The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly or via the rlcompleter module. Settings made using this module affect the behaviour of both the interpreter’s interactive prompt and the prompts offered by the raw_input() and input() built-in functions.

Note

On MacOS X the readline module can be implemented using the libedit library instead of GNU readline.

The configuration file for libedit is different from that of GNU readline. If you programmaticly load configuration strings you can check for the text “libedit” in readline.__doc__ to differentiate between GNU readline and libedit.

The readline module defines the following functions:

readline.parse_and_bind(string)

Parse and execute single line of a readline init file.

readline.get_line_buffer()

Return the current contents of the line buffer.

readline.insert_text(string)

Insert text into the command line.

readline.read_init_file([filename])

Parse a readline initialization file. The default filename is the last filename used.

readline.read_history_file([filename])

Load a readline history file. The default filename is ~/.history.

readline.write_history_file([filename])

Save a readline history file. The default filename is ~/.history.

readline.clear_history()

Clear the current history. (Note: this function is not available if the installed version of GNU readline doesn’t support it.)

New in version 2.4:

New in version 2.4.

readline.get_history_length()

Return the desired length of the history file. Negative values imply unlimited history file size.

readline.set_history_length(length)

Set the number of lines to save in the history file. write_history_file() uses this value to truncate the history file when saving. Negative values imply unlimited history file size.

readline.get_current_history_length()

Return the number of lines currently in the history. (This is different from get_history_length(), which returns the maximum number of lines that will be written to a history file.)

New in version 2.3:

New in version 2.3.