User Tools

Site Tools


zurich:python

Python startup

You can configure python using a startup file. Python runs whatever file the environment variable $PYTHONSTARTUP points to.

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

Example: History and Tab-Completion

create the file .pystartup

.pystartup
import atexit
import os
import readline
import rlcompleter
 
historyPath = os.path.expanduser("~/.pyhistory")
readline.parse_and_bind('tab: complete')
 
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

And add one of the following lines to your shell-rc file:

export PYTHONSTARTUP="$HOME/.pystartup"   # .bashrc
setenv PYTHONSTARTUP "$HOME/.pystartup"   # .cshrc
zurich/python.txt · Last modified: 2010/11/30 12:36 by nchiap