How to repeat last command in python interpreter shell?

后端 未结 26 1025
一个人的身影
一个人的身影 2020-11-29 16:43

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
         


        
相关标签:
26条回答
  • You didn't specify which environment. Assuming you are using IDLE.

    From IDLE documentation: Command history:

    Alt-p retrieves previous command matching what you have typed.
    Alt-n retrieves next.
          (These are Control-p, Control-n on the Mac)
    Return while cursor is on a previous command retrieves that command.
    Expand word is also useful to reduce typing.
    
    0 讨论(0)
  • 2020-11-29 16:59

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

    0 讨论(0)
  • 2020-11-29 16:59

    For anaconda for python 3.5, I needed to install ncurses

    conda install ncurses
    

    After the ncurses install tab complete, history, and navigating via left and right arrows worked in the interactive shell.

    0 讨论(0)
  • 2020-11-29 17:00
    alt+p  
    go into options tab
    configure idle
    Keys
    

    look under history-previous for the command, you can change it to something you like better once here.

    0 讨论(0)
  • 2020-11-29 17:01

    On CentOS, I fix this by

    yum install readline-devel
    

    and then recompile python 3.4.

    On OpenSUSE, I fix this by

    pip3 install readline
    

    Referring to this answer:https://stackoverflow.com/a/26356378/2817654. Perhaps "pip3 install readline" is a general solution. Haven't tried on my CentOS.

    0 讨论(0)
  • 2020-11-29 17:01

    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

    0 讨论(0)
提交回复
热议问题