Personal tools
You are here: Home CDAT Tips and Tricks Python Tips Autocompletion from command line.
Document Actions

Autocompletion from command line.

by Renata McCoy last modified 2007-05-08 10:49

Goal: Learn how to get autocompletion from command line in python.


  It is possible to automatically have Python suggest completion for words or possible function associated with an object, by pressing the "tab" key twice.
In order to accomplish this, create a file containing the following lines:

import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
Then you simply need to set your environment variable PYTHONSTARTUP to point to this file.

  After starting python, it will load this file (not if you tell it to run a script though) and you know have automatic completion.

Example:

python

import MV
MV.ar [tab][tab]

MV.arange MV.arcsin MV.arctan2
MV.around MV.arrayrangeMV.arccos
MV.arctan MV.argsort MV.array

Voila!

Powered by Plone