NORDITA logo University of Dundee
MHD Group
Postdoctoral Fellow
Simon Candelaresi
home publications/talks teaching cv computing links pictures/movies

Activate command history and CTRL+r history search in python

Create the file ~/.pyhistory
touch ~/.pyhistory
and edit your ~/.pythonrc:
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

References

http://docs.python.org/tutorial/interactive.html

home publications/talks teaching cv computing links pictures/movies