Prevent ipython from storing outputs in Out variable Prevent ipython from storing outputs in Out variable pandas pandas

Prevent ipython from storing outputs in Out variable


The first option you have is to avoid producing output. If you don't really need to see the intermediate results just avoid them and put all the computations in a single cell.

If you need to actually display that data you can use InteractiveShell.cache_size option to set a maximum size for the cache. Setting this value to 0 disables caching.

To do so you have to create a file called ipython_config.py (or ipython_notebook_config.py) under your ~/.ipython/profile_default directory with the contents:

c = get_config()c.InteractiveShell.cache_size = 0

After that you'll see:

In [1]: 1Out[1]: 1In [2]: Out[1]---------------------------------------------------------------------------KeyError                                  Traceback (most recent call last)<ipython-input-2-d74cffe9cfe3> in <module>()----> 1 Out[1]KeyError: 1

You can also create different profiles for ipython using the command ipython profile create <name>. This will create a new profile under ~/.ipython/profile_<name> with a default configuration file. You can then launch ipython using the --profile <name> option to load that profile.

Alternatively you can use the %reset out magic to reset the output cache or use the %xdel magic to delete a specific object:

In [1]: 1Out[1]: 1In [2]: 2Out[2]: 2In [3]: %reset outOnce deleted, variables cannot be recovered. Proceed (y/[n])? yFlushing output cache (2 entries)In [4]: Out[1]---------------------------------------------------------------------------KeyError                                  Traceback (most recent call last)<ipython-input-4-d74cffe9cfe3> in <module>()----> 1 Out[1]KeyError: 1In [5]: 1Out[5]: 1In [6]: 2Out[6]: 2In [7]: v = Out[5]In [8]: %xdel v    # requires a variable name, so you cannot write %xdel Out[5]In [9]: Out[5]     # xdel removes the value of v from Out and other caches---------------------------------------------------------------------------KeyError                                  Traceback (most recent call last)<ipython-input-9-573c4eba9654> in <module>()----> 1 Out[5]KeyError: 5