Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase IPython history length

I have tried increasing IPython history length following this post : Control ipython history length by changing c.TerminalInteractiveShell.history_length in ~/.ipython/profile_default/ipython_config.py.

The config file seems to be executed at startup (if I put print('test-startup') in the file, it's printed when I start IPython)

But it does not seems to have any influence, is there anyway to check the history size from inside the ipython (kinda like how you can do echo $HISTSIZE; echo $HISTFILESIZE in bash ?)

like image 633
Nihl Avatar asked Oct 09 '15 08:10

Nihl


2 Answers

In attempting to answer the question myself, I stumbled upon this question as well this question and found snippets that really didn't provide the OP with the complete, TL;DR information.

So for my own records and to make the answers on SO here more complete, I provided a quick implementation and check to "Increase iPython History Length."

Generate the iPython config file

$ ipython profile create <profile name>

I just wanted this for my default config, so I ran:

$ ipython profile create

Modify the ipython_config.py File

Running the above command creates an ipython_config.py file, which (on *.nix is stored at ~/.ipython/profile_default/ipython_config.py

These are the two lines that I uncommented and changed the values for:

enter image description here

Check to Ensure the Implementation Worked

Fire up iPython and run the commands found in the accepted answer above to ensure our new 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
like image 85
benjaminmgross Avatar answered Sep 28 '22 03:09

benjaminmgross


Using

In[3]: %config TerminalInteractiveShell.history_length
Out[3]: 10000
like image 44
donkopotamus Avatar answered Sep 28 '22 03:09

donkopotamus