Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import shelve
  2. from contextlib import closing
  3.  
  4.  
  5. def shelve_locals(filename, locals_):
  6. """
  7. Intended to be called as shelve_locals(filename, locals()) from a debug session
  8. and then loaded into another environment like an ipython notebook.
  9.  
  10. ex:
  11. from locus.pipe.utils.debug_utils import shelve_locals
  12. shelve_locals('debug.shelf',locals())
  13. """
  14. with closing(shelve.open(filename)) as shelf:
  15. for key, v in locals_.iteritems():
  16. if key in ['__builtins__', 'debug_utils']:
  17. pass
  18. else:
  19. try:
  20. shelf[key] = v
  21. except TypeError:
  22. print('TypeError shelving: {0}'.format(key))
  23. except Exception as e:
  24. print('Generic error shelving: {0}'.format(key))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement