Skip to content

Instantly share code, notes, and snippets.

@matterche
Last active December 15, 2023 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matterche/6190685b67bc9ddec537 to your computer and use it in GitHub Desktop.
Save matterche/6190685b67bc9ddec537 to your computer and use it in GitHub Desktop.
Enable Python REPL command history and tab completion
# Store this file in ~/.pystartup,
# set "export PYTHONSTARTUP=/home/user/.pystartup"
#
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.
import atexit
import os
import readline
import rlcompleter
readline.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
@ruiseixasm
Copy link

Will this enable tab auto completion in repl interactive mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment