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

后端 未结 10 1733
不知归路
不知归路 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:19

    Since the above only works for python 2.x for python 3.x (specifically 3.5) is similar but with a slight modification:

    import readline
    for i in range(readline.get_current_history_length()):
        print (readline.get_history_item(i + 1))
    

    note the extra ()

    (using shell scripts to parse .python_history or using python to modify the above code is a matter of personal taste and situation imho)

提交回复
热议问题