16

在这篇文章之后,我尝试增加 IPython 历史长度: 通过更改来控制 ipython 历史长度c.TerminalInteractiveShell.history_length~/.ipython/profile_default/ipython_config.py

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

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

4

2 回答 2

15

在尝试自己回答这个问题时,我偶然发现了这个问题以及这个问题,并发现确实没有为 OP 提供完整的 TL;DR 信息的片段。

因此,为了我自己的记录并让这里的 SO 答案更完整,我提供了一个快速实现并选中“增加 iPython 历史长度”。

生成iPython配置文件

$ ipython profile create <profile name>

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

$ ipython profile create

修改ipython_config.py文件

运行上述命令会创建一个ipython_config.py文件,该文件(on*.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
于 2018-04-13T16:08:50.907 回答
11

使用

In[3]: %config TerminalInteractiveShell.history_length
Out[3]: 10000
于 2015-10-09T08:34:01.507 回答