Python:readline
lastmod 2026-11-10created 2015-12-193 edits
readline is a Python standard library module that provides an interface to the GNU readline library. It enables line editing, command history, and tab completion in the interactive interpreter and in input() calls, and is used together with the rlcompleter module. Functions for reading and writing history files let input history persist across sessions.
Interactive Input
import atexit
import os
import readline
import rlcompleter
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