This documentation is for an old version of IPython. You can find docs for newer versions here.
%store magic for lightweight persistence.
Stores variables, aliases and macros in IPython’s database.
To automatically restore stored variables at startup, add this to your
c.StoreMagics.autorestore = True
Lightweight persistence for python variables.
In : l = ['hello',10,'world'] In : %store l In : exit (IPython session is closed and started again...) [email protected]:~$ ipython In : l NameError: name 'l' is not defined In : %store -r In : l Out: ['hello', 10, 'world']
%store- Show list of all variables and their current
%store spam- Store the current value of the variable spam
%store -d spam- Remove the variable and its value from storage
%store -z- Remove all variables from storage
%store -r- Refresh all variables from store (overwrite
%store -r spam bar- Refresh specified variables from store
(delete current val)
%store foo >a.txt- Store value of foo to new file a.txt
%store foo >>a.txt- Append value of foo to file a.txt
It should be noted that if you change the value of a variable, you need to %store it again if you want to persist the new value.
Note also that the variables will need to be pickleable; most basic python types can be safely %store’d.
Also aliases can be %store’d across sessions.