Tab-completion in Python interpreter in OS X Terminal
This should work under Leopard's python:
import rlcompleterimport readlinereadline.parse_and_bind ("bind ^I rl_complete")
Whereas this one does not:
import readline, rlcompleterreadline.parse_and_bind("tab: complete")
Save it in ~/.pythonrc.py and execute in .bash_profile
export PYTHONSTARTUP=$HOME/.pythonrc.py
here is a full cross platform version of loading tab completion for Windows/OS X/Linux in one shot:
#Code UUID = '9301d536-860d-11de-81c8-0023dfaa9e40'import systry: import readlineexcept ImportError: try: import pyreadline as readline # throw open a browser if we fail both readline and pyreadline except ImportError: import webbrowser webbrowser.open("http://ipython.scipy.org/moin/PyReadline/Intro#line-36") # throw open a browser #passelse: import rlcompleter if(sys.platform == 'darwin'): readline.parse_and_bind ("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete")
To avoid having to use more GPL code, Apple doesn't include a real readline. Instead it uses the BSD-licensed libedit, which is only mostly-readline-compatible. Build your own Python (or use Fink or MacPorts) if you want completion.