Skip to content

Instantly share code, notes, and snippets.

@mludvig
Created November 29, 2016 10:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mludvig/a0a72e4e363e67101d673f11da2160d7 to your computer and use it in GitHub Desktop.
Save mludvig/a0a72e4e363e67101d673f11da2160d7 to your computer and use it in GitHub Desktop.
# startup script for python to enable saving of interpreter history and
# enabling name completion
# import needed modules
import atexit
import os
import readline
import rlcompleter
# where is history saved
historyPath = os.path.expanduser("~/.pyhistory")
# handler for saving history
def save_history(historyPath=historyPath):
import readline
try:
readline.write_history_file(historyPath)
except:
pass
# read history, if it exists
if os.path.exists(historyPath):
readline.set_history_length(10000)
readline.read_history_file(historyPath)
# register saving handler
atexit.register(save_history)
# enable completion
readline.parse_and_bind('tab: complete')
# cleanup
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