How to repeat last command in python interpreter shell?

后端 未结 26 1028
一个人的身影
一个人的身影 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条回答
  • 2020-11-29 17:03

    Ipython isn't allways the way... I like it pretty much, but if you try run Django shell with ipython. Something like>>>

    ipython manage.py shell
    

    it does'n work correctly if you use virtualenv. Django needs some special includes which aren't there if you start ipython, because it starts default system python, but not that virtual.

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

    If you use Debian Jessie run this to fix your system installation 2.7.9

    sudo apt-get install libncurses5-dev libncursesw5-dev
    

    To fix my other 3.5.2 installation which I installed with pyenv :

    pip install readline
    

    Sources:

    [1] https://www.cyberciti.biz/faq/linux-install-ncurses-library-headers-on-debian-ubuntu-centos-fedora/

    [2] https://github.com/yyuu/pyenv/issues/240

    [3] https://stackoverflow.com/a/40229934/332788

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

    I don't understand why there are so many long explanations about this. All you have to do is install the pyreadline package with:

    pip install pyreadline
    
    sudo  port install py-readline (on Mac)
    

    (Assuming you have already installed PIP.)

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

    In my mac os python3 you can use: control+p early command contrlo+n next command

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

    This can happen when you run python script.py vs just python to enter the interactive shell, among other reasons for readline being disabled.

    Try:

    import readline
    
    0 讨论(0)
  • 2020-11-29 17:07

    For repeating the last command in python, you can use <Alt + n> in windows

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