Loading

Python shell显示历史命令方法

背景

使用python shell做简单的调试和画图,
希望能像bash一样通过history查看历史命令

实现

Python3一句话方法

import readline; print('\n'.join([str(readline.get_history_item(i + 1)) for i in range(readline.get_current_history_length())]))

Python2一句话方法

import readline; print '\n'.join([str(readline.get_history_item(i + 1)) for i in range(readline.get_current_history_length())])

参考

macos - How do you see the entire command history in interactive Python? - Stack Overflow

posted @ 2022-05-26 14:15  azureology  阅读(815)  评论(0)    收藏  举报