2009
10.10

One of the things that used to bug me a bit about using the python interactive console was that it didn’t support tab completion. So here a short “how to”, written for Linux and Mac users. Windows users – please see the tailing note.

In your home directory create a new file “.pystartup” and copy the below python script into it.

import readline
import rlcompleter
import atexit
import os
 
# tab completion
readline.parse_and_bind('tab: complete')
 
# history file
history_file = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
     readline.read_history_file(history_file)
except IOError:
     pass
 
atexit.register(readline.write_history_file, history_file)
del os, history_file, readline, rlcompleter

Then open the .bashrc file in your home directory and add the following line to it:

export PYTHONSTARTUP=~/.pystartup

Thats it folks… actually it pretty easy to do this in Windows, just set a new environment variable as an administrator in the system preferences pointing to the above files location.

4 comments so far

Add Your Comment
  1. sudo apt-get install ipython

    :)

  2. Welcome Morgan :) If I’d known it was that easy…. LOL!

  3. sudo apt-get install bpython

    yes bpython and not ipython:

    completion à la eclipse/komodo/etc.

    only available on latest ubuntu I guess

  4. Nice one David, just installed it on Ubuntu Server 9.10 – is available in repo. Thanks!