增加 IPython 历史长度

Increase IPython history length

我已经尝试增加 IPython 历史记录长度 post : Control ipython history length 通过更改 ~/.ipython/profile_default/ipython_config.py 中的 c.TerminalInteractiveShell.history_length

配置文件似乎是在启动时执行的(如果我把print('test-startup')放在文件中,它会在我启动时打印出来IPython)

但它似乎没有任何影响,无论如何可以从 ipython 内部检查历史大小(有点像你如何在 bash 中执行 echo $HISTSIZE; echo $HISTFILESIZE ? )

正在使用

In[3]: %config TerminalInteractiveShell.history_length
Out[3]: 10000

在试图自己回答这个问题时,我偶然发现了这个问题 as well this question 并发现了一些片段,这些片段确实没有为 OP 提供完整的 TL;DR 信息。

因此,为了我自己的记录并使此处的答案更加完整,我提供了一个快速实施并检查 "Increase iPython History Length."

生成 iPython 配置文件

$ ipython profile create <profile name>

我只是想要这个作为我的默认配置,所以我 运行:

$ ipython profile create

修改ipython_config.py文件

运行 上述命令创建了一个 ipython_config.py 文件,该文件(在 *.nix 上存储在 ~/.ipython/profile_default/ipython_config.py

这些是我取消注释并更改值的两行:

检查以确保实施有效

启动 iPython 和 运行 在上面接受的答案中找到的命令,以确保我们的新 history_length = 100,000.

benjamingross (develop*)$ ipython
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:14:23)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.3.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %config TerminalInteractiveShell.history_length
Out[1]: 100000