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 .auto_completion_python_shell.py 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.

export PYTHONSTARTUP="$HOME/.auto_complete_python_shell.py"

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 some_script.py (not under interactive script shell).

Cheers!

Arulalan.T

Unknown's avatar

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 comment