As we know, if we stop the kernel, when we re-open the file, all outputs are lost.
Is there any way we can save them and reload (resume) it later especially on another device?
As we know, if we stop the kernel, when we re-open the file, all outputs are lost.
Is there any way we can save them and reload (resume) it later especially on another device?
If you have in-memory objects you are trying to store you can look into Pickle, it's part of the standard library.
import pickle
# Create a large object
oldObj = [n for n in range(10**3)]
print(len(oldObj), type(oldObj))
# <class 'list'> 1000
# Save to file
with open('myFile.pkl', 'wb') as file:
pickle.dump(oldObj, file)
# --- you can send the file to someone else, or stop the kernel
# Load from file
with open('myFile.pkl', 'rb') as file:
newObj = pickle.load(file)
print(len(newObj), type(newObj))
# <class 'list'> 1000
This works with nearly any native Python type, with a few exceptions. There is another library called dill
that extends this functionality even further (it uses the same syntax)
$ pip install dill
EDIT: Upon re-reading your post, I am unsure what you mean by "output". If you simply mean the literal printed output of cells, that should persist as long as you are saving the notebook after execution. You also can save the notebook as a static document in order to preserve its visual state in a more robust manner. Some of the common export types are HTML, PDF, and Markdown.
$ jupyter nbconvert --help