If I have several IPython notebooks running on the same server. Is there any way to share data between them? For example, importing a variable from another notebook? Thanks!
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
This works for me :
I've successfully tested with sklearn dataset :
in notebook to read data :
src : https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/
IPython supports the
%store
magic (here is the documentation). It seems to have the same constraints of pickle: if the file can be pickled it will also be storable.Anyway, it will work for sure with common Python types. Here's a basic example:
Then on a different IPython notebook it will be sufficient to type:
If your data is in a single variable then have a try at saving it to a file using the
%save
magic in one notebook and then reading it back in another.The one difficulty is that the text file will contain the data but no variable definition so I usually contatenate it with a variable definition and then
exec
the result.I believe that theoretically you should be able to do so with messaging, though I would have to dig a lot deeper to figure it out.
Why would you need this capability though?