Friday, August 21, 2009

Tab Auto-Completion in Python Shell

Strangely enough, I discovered that I do not get bash-like auto-completion in my python interactive shell.

Looking up helped.

Just need to have a file called .pythonrc in your home directory containing the following:

import os
import sys

import readline
except ImportError:
print "Module readline not available."
import rlcompleter
readline.parse_and_bind("tab: complete")

Apparently, that was not enough. I also needed to add the following line to my .bashrc file (in my home directory again).

export PYTHONSTARTUP=~/.pythonrc

That's all. Open a new shell and start the python shell.

And enjoy auto-completion!


Anonymous said...

Or you can use ipython. :-)

John said...

Thank you for the tip =).

Michael Scherer said...

We have enabled this in Mandriva by default without people complaining since some years, so I think this would be safe and useful to be enabled on fedora ( and in other distribution too ).

Abhishek said...

It is by default there in openSuse

Yankee said...

Why not convince upstream python to include this as a default so that its expected behavior for everyone? Then there isnt a patchwork of expected behavior, which is the current situation.

$hRiNk said...

Rinkesh said...

It appears that you’ve put a solid amount of effort into your article and I want to see a lot more of these on the Internet these days. I really got a quetch out of your post. I do not have a bunch to to say in reply, I only wanted to register to say great work.
We buy Any Car

Clive said...

Just studying python at cambridge so thanks for the info.

buy my car

Leire said...

We have enabled this in Mandriva by default, love python !

sell my car

anon said...

just use ipython in future.

Manchester block paving

The Motoring said...

Thanks for the tips about Auto compilation. Keep going. I follow you.

Anonymous said...

I really liked your article. Keep up the good work.I love extreme bondage sex

Anonymous said...

I was interested know about it lesbian bondage

Anthon van der Neut said...

The code looks the same as Irmen's blog from 2004 ( )

But why include import os and import sys and not use them?