Skip to content

Instantly share code, notes, and snippets.

@lhk
Created November 18, 2019 16:42
Show Gist options
  • Save lhk/996100c444242f9efdf7fb403204d795 to your computer and use it in GitHub Desktop.
Save lhk/996100c444242f9efdf7fb403204d795 to your computer and use it in GitHub Desktop.
import shelve
def save_scope(session_id='default'):
filename = f'/tmp/{session_id}.out'
shelf = shelve.open(filename, 'n')
for name in dir():
try:
shelf[name] = globals()[name]
except Exception as e:
pass
shelf.close()
def load_scope(session_id='default'):
filename = f'/tmp/{session_id}.out'
shelf = shelve.open(filename)
for name in shelf:
globals()[name] = shelf[name]
shelf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment