How do you see the entire command history in interactive Python?

后端 未结 10 1806
不知归路
不知归路 2020-11-30 16:36

I\'m working on the default python interpreter on Mac OS X, and I Cmd+K (cleared) my earlier commands. I can go through them one by one using the arrow

10条回答
  •  孤城傲影
    2020-11-30 17:16

    @Jason-V, it really help, thanks. then, i found this examples and composed to own snippet.

    #!/usr/bin/env python3
    import os, readline, atexit
    python_history = os.path.join(os.environ['HOME'], '.python_history')
    try:
      readline.read_history_file(python_history)
      readline.parse_and_bind("tab: complete")
      readline.set_history_length(5000)
      atexit.register(readline.write_history_file, python_history)
    except IOError:
      pass
    del os, python_history, readline, atexit 
    

提交回复
热议问题