Skip to content

Instantly share code, notes, and snippets.

@jj-github-jj
Last active January 5, 2022 04:59
Show Gist options
  • Save jj-github-jj/704dd32b9d3a7bad866910acea4e57c9 to your computer and use it in GitHub Desktop.
Save jj-github-jj/704dd32b9d3a7bad866910acea4e57c9 to your computer and use it in GitHub Desktop.
save reload plotly
def shelve_multiple(list_of_objects=[],fname=''):
""" not providing filename, uses default current notebook name but slow ipynbname function
shelve files are fname.shelf.dir,.data, and .bak(?)
copy these files with ipynb files to save restore objects without re-running
"""
import ipynbname
if fname =='':
fname=ipynbname.name() #use note book name but way too slow so best to pass filename
d=shelve.open(fname +'.shelf')
for i,x in enumerate(list_of_objects):
d[str(i)]=x
d.close()
return (fname)
def load_mulitple_from_shelve(fname):
loadlist=[]
d=shelve.open(fname +'.shelf')
for i in range (100): #upto 100 objects for now
if (str(i) in d) :
loadlist.append(d[str(i)])
else:
break
return (loadlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment