I have a string variable I've defined in one Jupyter notebook that I'd like to use in another Jupyter notebook. I know from here that %store is an approach, but when I use %store -r <variable>
in either Jupyter notebook, I obtain the below errors ending in
TypeError: 'PickleShareDB' object is not subscriptable when using %store
Below is the full output. I installed pickleshare by running pip install pickleshare
in terminal.
Trying to use %store -r
in Jupyter notebook A (notebook where string variable defined)
# Retrieving stored string_var from notebook A
from pickleshare import *
string_var = "hi"
%store string_var
%store -r string_var
Stored 'string_var' (str)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[27], line 5
4 get_ipython().run_line_magic('store', 'string_var')
----> 5 get_ipython().run_line_magic('store', '-r string_var')
File ~/Library/Python/3.9/lib/python/site-packages/IPython/core/interactiveshell.py:2456, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2454 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2455 with self.builtin_trap:
-> 2456 result = fn(*args, **kwargs)
2458 # The code below prevents the output from being displayed
2459 # when using magics with decorator @output_can_be_silenced
2460 # when the last Python token in the expression is a ';'.
2461 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File ~/Library/Python/3.9/lib/python/site-packages/IPython/extensions/storemagic.py:148, in StoreMagics.store(self, parameter_s)
146 for arg in args:
147 try:
--> 148 obj = db['autorestore/' + arg]
149 except KeyError:
150 try:
TypeError: 'PickleShareDB' object is not subscriptable
Trying to use %store -r
in Jupyter notebook B, where I'd like to retrieve string_var from notebook A
# Retrieving stored string_var from notebook A
from pickleshare import *
%store -r string_var
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[37], line 2
1 from pickleshare import *
----> 2 get_ipython().run_line_magic('store', '-r string_var')
File ~/Library/Python/3.9/lib/python/site-packages/IPython/core/interactiveshell.py:2456, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2454 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2455 with self.builtin_trap:
-> 2456 result = fn(*args, **kwargs)
2458 # The code below prevents the output from being displayed
2459 # when using magics with decorator @output_can_be_silenced
2460 # when the last Python token in the expression is a ';'.
2461 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File ~/Library/Python/3.9/lib/python/site-packages/IPython/extensions/storemagic.py:148, in StoreMagics.store(self, parameter_s)
146 for arg in args:
147 try:
--> 148 obj = db['autorestore/' + arg]
149 except KeyError:
150 try:
TypeError: 'PickleShareDB' object is not subscriptable
Thank you.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744174113a4561671.html
评论列表(0条)