By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,154 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,154 IT Pros & Developers. It's quick & easy.

auto-completion history

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
porterboy wrote:
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...

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


It's not in python, it's in readline library. To read the documentation
do 'man readline'

readline.parse_and_bind('"\e[A": history-search-backward')

works for me. To find out what your up arrow key sends remove
\e[A and hit on your keyboard Control-v and then up arrow.

Serge.

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.