-
-
Save avicoder/13c90827934b5207b173eb8d55da013a to your computer and use it in GitHub Desktop.
Enable Python REPL command history and tab completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment