Persistent Python Command-Line History

 ̄綄美尐妖づ 提交于 2019-12-02 23:07:41

I think the suggestions in the Python documentation pretty much cover what you want. Look at the example pystartup file toward the end of section 13.3:

or see this page:

But, for an out of the box interactive shell that provides all this and more, take a look at using IPython:

Try using IPython as a python shell. It already has everything you ask for. They have packages for most popular distros, so install should be very easy.

Persistent history has been supported out of the box since Python 3.4. See this bug report.

Use PIP to install the pyreadline package:

pip install pyreadline

If all you want is to use interactive history substitution without all the file stuff, all you need to do is import readline:

import readline

And then you can use the up/down keys to navigate past commands. Same for 2 or 3.

This wasn't clear to me from the docs, but maybe I missed it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!