增加IPython历史记录长度

17

我尝试按照此帖子的方法增加IPython历史记录长度,通过更改~/.ipython/profile_default/ipython_config.py中的c.TerminalInteractiveShell.history_length参数。

这个配置文件似乎在启动时被执行(如果我在文件中放置print('test-startup'),则在启动IPython时会打印该语句)。

但它似乎没有任何影响,有没有办法从IPython内部检查历史记录大小(类似于在bash中可以执行echo $HISTSIZE; echo $HISTFILESIZE?)

2个回答

18

在试图回答这个问题时,我偶然发现了这个问题和这个问题,并找到了一些片段,这些片段并没有为OP提供完整的TL;DR信息。

因此,为了记录下来,并使SO上的答案更完整,我提供了一个快速实现和检查以“增加iPython历史记录长度”。

生成iPython配置文件

$ ipython profile create <profile name>

我只是想将其作为我的默认配置,所以我运行了:

$ ipython profile create

修改 ipython_config.py 文件

执行上述命令将创建一个名为 ipython_config.py 的文件,(在 *.nix 上)该文件存储在 ~/.ipython/profile_default/ipython_config.py

以下是我取消注释并更改值的两行代码:

enter image description here

检查是否成功实现

启动 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

非常感谢您提供如此详细的答案! :) - MaxU - stand with Ukraine

11

使用

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接