How do I repeat the last command? The usual keys: Up, Ctrl+Up, Alt-p don't work. They produce nonsensical characters.
(ve)[kakarukeys@localhost ve]$ python
Python 2.6.6 (r266:84292, Nov 15 2010, 21:48:32)
[GCC 4.4.4 20100630 (Red Hat 4.4.4-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world"
hello world
>>> ^[[A
File "<stdin>", line 1
^
SyntaxError: invalid syntax
>>> ^[[1;5A
File "<stdin>", line 1
[1;5A
^
SyntaxError: invalid syntax
>>> ^[p
File "<stdin>", line 1
p
^
SyntaxError: invalid syntax
>>>
Up Arrow works only in Python command line.
In IDLE (Python GUI) the defaults are: Alt-p : retrieves previous command matching what you have typed. Alt-n : retrieves next... In Python 2.7.9 for example, you can see/change the Action Keys selecting: Options -> Configure IDLE -> (Tab) Keys
You don't need a custom script like pyfunc's answer for OSX (at least on mavericks). In Idle click on Idle -> Preferences -> Keys, locate "history-next" and "history-previous", and either leave them with their default keyboard shortcut or assign "up arrow" and "down arrow" per typical expected terminal behavior.
This is on Idle 2.7 on OSX Mavericks.
For anaconda for python 3.5, I needed to install
ncurses
After the
ncurses
install tab complete, history, and navigating via left and right arrows worked in the interactive shell.If using MacOSX, press
control p
to cycle up andcontrol n
to cycle down. I am using IDLE Python 3.4.1 Shell.Ctrl+p is the normal alternative to the up arrow. Make sure you have gnu readline enabled in your Python build.
By default use ALT+p for previous command, you can change to Up-Arrow instead in IDLE GUi >> OPtions >> Configure IDLE >>Key >>Custom Key Binding It is not necesary to run a custom script, besides readlines module doesnt run in Windows. Hope That Help. :)