auto-completion history

porterboy porterboy76 at yahoo.com
Fri Feb 25 04:29:19 EST 2005


Hi Folks,

I have auto-completion set up in my python interpreter so that if I
hit the tab key it will complete a variable or a python command*. eg.
if I type
>>> imp
and if I then hit the tab key, the interpreter will complete it to...
>>> import

Now, I also use Matlab at the command line a lot and it has a nice
additional auto-completion feature, whereby, if you type a few letters
and hit the up-arrow, it will go back to the last command you typed
that began with those letters. If you keep hitting up-arrow it will
cycle through all the commands you typed beginning with these letters.
eg. if I type...

>>> import datetime
>>> import sys
>>> today = datetime.date.today()
>>> imp

After typing the last imp I hit up-arrow once I would like the history
to return to
>>> import sys
and if I hit twice, I would like to go to
>>> import datetime

Does a feature like this already exist in python???

Thanks

The PorterBoy - "Lovely day for a Guinness" 

ps...
* If you are unsure how to set up auto completion (UNIX only) ...

1. Include this line in your .tcshrc file (or equivalent in .bashrc):
       setenv PYTHONSTARTUP "$HOME/.pythonrc.py"
2. In the file ~/.pythonrc.py include the lines:
       import rlcompleter, readline
       readline.parse_and_bind('tab: complete')
       del rlcompleter, readline
3. For the effect to work, open a new terminal, and type python. If
you do not fire up a new session, python has no way to become aware of
your changes.



More information about the Python-list mailing list