Python startup (command completion & history)
August 21st, 2008 by exhuma.twn
If you want command completion and a history in your python shell, export the PYTHONSTARTUP env var (export PYTHONSTARTUP=$HOME/.pystartup) in your bashrc and create a file ~/.pystartup with the following contents:
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)
readline.parse_and_bind('tab: complete')
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
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)
readline.parse_and_bind('tab: complete')
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
Posted in Python | No Comments »