How to repeat last command in python interpreter shell?

后端 未结 26 1175
一个人的身影
一个人的身影 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 16:52

    I use the following to enable history on python shell.

    This is my .pythonstartup file . PYTHONSTARTUP environment variable is set to this file path.

    # python startup file 
    import readline 
    import rlcompleter 
    import atexit 
    import os 
    # tab completion 
    readline.parse_and_bind('tab: complete') 
    # history file 
    histfile = os.path.join(os.environ['HOME'], '.pythonhistory') 
    try: 
        readline.read_history_file(histfile) 
    except IOError: 
        pass 
    atexit.register(readline.write_history_file, histfile) 
    del os, histfile, readline, rlcompleter
    

    You will need to have the modules readline, rlcompleter to enable this.

    Check out the info on this at : http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP.

    Modules required:

    1. http://docs.python.org/library/readline.html
    2. http://docs.python.org/library/rlcompleter.html

提交回复
热议问题