auto-completion history

P

porterboy

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

After typing the last imp I hit up-arrow once I would like the history
to return to
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.
 
S

Serge Orlov

porterboy said:
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top