First you'll need to add a line to your .bashrc or .profile setting your PYTHONSTARTUP environment variable
# ~/.bashrc export PYTHONSTARTUP=$HOME/.pythonstartup.py
Then copy this scripts contents to file your new environment variable points to
# ~/.pythonstartup.py try: import readline import rlcompleter import atexit import os except ImportError: print "Python shell enhancement modules not available." else: histfile = os.path.join(os.environ["HOME"], ".pythonhistory") import rlcompleter readline.parse_and_bind("tab: complete") if os.path.isfile(histfile): readline.read_history_file(histfile) atexit.register(readline.write_history_file, histfile) del os, histfile, readline, rlcompleter, atexit print "Python shell history and tab completion are enabled."
That's it. Now anytime you pop into the python shell you'll have history from previous sessions as well as tab completion. Enjoy!
Edit: If you're not running the latest version of OSX you may need to change the readline.pasre_and_bind line to the following
#readline.parse_and_bind("tab: complete") readline.parse_and_bind("bind ^I rl_complete")