增加IPython历史记录长度

2024-09-27 19:15:54 发布

您现在位置:Python中文网/ 问答频道 /正文

在这篇文章之后,我尝试增加IPython的历史长度: Control ipython history length通过在~/.ipython/profile_default/ipython_config.py中更改c.TerminalInteractiveShell.history_length。在

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

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


Tags: pyechoconfigdefault配置文件ipython历史profile
2条回答

使用

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

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

因此,对于我自己的记录,为了让这里的答案更完整,我提供了一个快速实现和检查“增加iPython历史长度”

生成iPython配置文件

$ ipython profile create <profile name>

我只想把它作为我的默认配置,所以我运行:

^{pr2}$

修改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

相关问题 更多 >

    热门问题