Proofs of concepts using Pickle and Dill through Jupiter notebooks
Dill extends python’s pickle module for serializing and de-serializing python objects to the majority of the built-in python types.
Serialization is the process of converting an object to a byte stream, and the inverse of which is converting a byte stream back to on python object hierarchy.
If you don't have Dill installed yet, please run the following command:
pip install dill
Requirement already satisfied: dill in /home/ced/anaconda3/lib/python3.7/site-packages (0.3.1.1)
Note: you may need to restart the kernel to use updated packages.
import dill
favorite_color = {"lion":"yellow", "kitty":"red"}
dill.dump_session('save-dill-notebook_env.db')
print(favorite_color)
{'lion': 'yellow', 'kitty': 'red'}
print(favorite_color)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-9fd5ad14973e> in <module>
----> 1 print(favorite_color)
NameError: name 'favorite_color' is not defined
import dill
dill.load_session('save-dill-notebook_env.db')
print(favorite_color)
{'lion': 'yellow', 'kitty': 'red'}
This Pickle exemple have been made using Python UsingPickle doc
import pickle
favorite_color = {"lion":"yellow", "kitty":"red"}
pickle.dump( favorite_color, open( "save-pickle.p", "wb"))
print(favorite_color)
{'lion': 'yellow', 'kitty': 'red'}
print(favorite_color)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-9fd5ad14973e> in <module>
----> 1 print(favorite_color)
NameError: name 'favorite_color' is not defined
import pickle
favorite_color = pickle.load( open("save-pickle.p", "rb"))
print(favorite_color)
{'lion': 'yellow', 'kitty': 'red'}