%load_ext ipycache
%%cache
a = 1
UsageError: too few arguments
%%cache myvars.pkl a
a = 1
Skipped the cell's code and loaded variables a from file 'myvars.pkl'.
%%cache myvars.pkl a b c
a = 1
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-4-89b13d48d617> in <module>() ----> 1 get_ipython().run_cell_magic(u'cache', u'myvars.pkl a b c', u'a = 1') d:\git\ipython\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2137 magic_arg_s = self.var_expand(line, stack_depth) 2138 with self.builtin_trap: -> 2139 result = fn(magic_arg_s, cell) 2140 return result 2141 D:\Git\ipycache\ipycache.py in cache(self, line, cell) d:\git\ipython\IPython\core\magic.py in <lambda>(f, *a, **k) 189 # but it's overkill for just that one bit of state. 190 def magic_deco(arg): --> 191 call = lambda f, *a, **k: f(*a, **k) 192 193 if callable(arg): D:\Git\ipycache\ipycache.py in cache(self, line, cell) 204 ip_user_ns=ip.user_ns, 205 ip_run_cell=ip.run_cell, --> 206 ip_push=ip.push, 207 ) 208 D:\Git\ipycache\ipycache.py in cache(cell, path, vars, ip_user_ns, ip_run_cell, ip_push, force, read, verbose) 139 else: 140 # Load the variables from cache in inject them in the namespace. --> 141 ip_push(load_vars(path, vars)) 142 143 if verbose: D:\Git\ipycache\ipycache.py in load_vars(path, vars) 95 raise ValueError(("The following variables could not be loaded " 96 "from the cache: {0:s}").format( ---> 97 ', '.join(["'{0:s}'".format(var) for var in missing_vars]))) 98 99 return cache ValueError: The following variables could not be loaded from the cache: 'c'
%%cache myvars.pkl a
a = 2
Skipped the cell's code and loaded variables a from file 'myvars.pkl'.
a
3
%%cache myvars.pkl a -f
a = 2
Saved variables a to file 'myvars.pkl'.
a
2
%%cache myvars.pkl a -r
a = 3
Skipped the cell's code and loaded variables a from file 'myvars.pkl'.
a
2
%%cache myvars.pkl a,b
a = 3
b = 2
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-11-3e75ebc75afa> in <module>() ----> 1 get_ipython().run_cell_magic(u'cache', u'myvars.pkl a,b', u'a = 3\nb = 2') d:\git\ipython\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2137 magic_arg_s = self.var_expand(line, stack_depth) 2138 with self.builtin_trap: -> 2139 result = fn(magic_arg_s, cell) 2140 return result 2141 D:\Git\ipycache\ipycache.py in cache(self, line, cell) d:\git\ipython\IPython\core\magic.py in <lambda>(f, *a, **k) 189 # but it's overkill for just that one bit of state. 190 def magic_deco(arg): --> 191 call = lambda f, *a, **k: f(*a, **k) 192 193 if callable(arg): D:\Git\ipycache\ipycache.py in cache(self, line, cell) 204 ip_user_ns=ip.user_ns, 205 ip_run_cell=ip.run_cell, --> 206 ip_push=ip.push, 207 ) 208 D:\Git\ipycache\ipycache.py in cache(cell, path, vars, ip_user_ns, ip_run_cell, ip_push, force, read, verbose) 139 else: 140 # Load the variables from cache in inject them in the namespace. --> 141 ip_push(load_vars(path, vars)) 142 143 if verbose: D:\Git\ipycache\ipycache.py in load_vars(path, vars) 95 raise ValueError(("The following variables could not be loaded " 96 "from the cache: {0:s}").format( ---> 97 ', '.join(["'{0:s}'".format(var) for var in missing_vars]))) 98 99 return cache ValueError: The following variables could not be loaded from the cache: 'ab'
%%cache myvars.pkl a, b
a = 3
b = 2
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-12-7c72d1311f89> in <module>() ----> 1 get_ipython().run_cell_magic(u'cache', u'myvars.pkl a, b', u'a = 3\nb = 2') d:\git\ipython\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell) 2137 magic_arg_s = self.var_expand(line, stack_depth) 2138 with self.builtin_trap: -> 2139 result = fn(magic_arg_s, cell) 2140 return result 2141 D:\Git\ipycache\ipycache.py in cache(self, line, cell) d:\git\ipython\IPython\core\magic.py in <lambda>(f, *a, **k) 189 # but it's overkill for just that one bit of state. 190 def magic_deco(arg): --> 191 call = lambda f, *a, **k: f(*a, **k) 192 193 if callable(arg): D:\Git\ipycache\ipycache.py in cache(self, line, cell) 204 ip_user_ns=ip.user_ns, 205 ip_run_cell=ip.run_cell, --> 206 ip_push=ip.push, 207 ) 208 D:\Git\ipycache\ipycache.py in cache(cell, path, vars, ip_user_ns, ip_run_cell, ip_push, force, read, verbose) 139 else: 140 # Load the variables from cache in inject them in the namespace. --> 141 ip_push(load_vars(path, vars)) 142 143 if verbose: D:\Git\ipycache\ipycache.py in load_vars(path, vars) 95 raise ValueError(("The following variables could not be loaded " 96 "from the cache: {0:s}").format( ---> 97 ', '.join(["'{0:s}'".format(var) for var in missing_vars]))) 98 99 return cache ValueError: The following variables could not be loaded from the cache: 'b'
%%cache myvars.pkl a, b -f
a = 3
b = 2
Saved variables a, b to file 'myvars.pkl'.
a, b
(3, 2)
import os
os.remove('myvars.pkl')