Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import shelve
- from contextlib import closing
- def shelve_locals(filename, locals_):
- """
- Intended to be called as shelve_locals(filename, locals()) from a debug session
- and then loaded into another environment like an ipython notebook.
- ex:
- from locus.pipe.utils.debug_utils import shelve_locals
- shelve_locals('debug.shelf',locals())
- """
- with closing(shelve.open(filename)) as shelf:
- for key, v in locals_.iteritems():
- if key in ['__builtins__', 'debug_utils']:
- pass
- else:
- try:
- shelf[key] = v
- except TypeError:
- print('TypeError shelving: {0}'.format(key))
- except Exception as e:
- print('Generic error shelving: {0}'.format(key))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement