Setting Auto Completion in Python Shell

Dear Friends,

Today I found very useful tips from the CDAT document page about how to make auto completion in python shell.

#!/usr/bin/env python
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")

Save the above code as inyour home directory of your home directory in *nix system.

Then open the .bashrc by

$ gedit .bashrc

add the following line at the end of the file.


Save the file and close it. Close the terminal.

Now reopen the terminal, issue the command python

>>> im[tab] [tab]
it should automatically complete the import command.

It also displays the available methods, and variables of any object in the shell prompt.

Of-course it will not be fashion as "bpython" and "ipython"

But in some situations, python shell is best compare to bpython when we accessing large set of data.

In some cases bpython ncurses fails to handle large set of data…

Those cases we can apply our own PYTHONSTARTUP script to make it as auto complete commands…

Note : This auto completion will works only under shell, not under $python -i (not under interactive script shell).




About arulalant

Currently working as "Project Scientist – C" in National Centre for Medium Range Weather Forecasting (NCMRWF), MoES, Noida, India
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s