You can use the same magic commands . Cell magic : %%cache in an IPython laptop can be used to cache the results and results of lengthy calculations in a persistent pickle file. Useful when some calculations on a laptop are long and you want to easily save the results in a file.
To use it on your laptop, you first need to install the ipycache module, since this magic Cell command is not a built-in magic command.
then load the module into your notepad:
%load_ext ipycache
Then create a cell with:
%%cache mycache.pkl var1 var2 var1 = 1
When you run this cell for the first time, the code is executed, and the var1 and var2 variables are stored in mycache.pkl in the current directory along with the outputs. Rich output is only displayed if you are using the IPython version for development. When you run this cell again, the code is skipped, the variables are loaded from the file and entered into the namespace, and the outputs are restored to the laptop.
Alternatively, use $file_name instead of mycache.pkl , where file_name is a variable containing the path to the file used for caching.
Use the --force or -f option to force cell execution and overwrite the file.
Use the --read or -r option to prevent the cell from executing and always load variables from the cache. An exception occurs if the file does not exist.
ref: github ipycache storage and laptop example
hxysayhi
source share