2

When working in R, one has the ability to save the entire "workspace", variables, output, etc... to an image file using "save.image()". Is there something equivalent in Python?

Thank you.

Thomas Moore
  • 941
  • 2
  • 11
  • 17
  • Possible duplicate of [How can I save all the variables in the current python session?](https://stackoverflow.com/questions/2960864/how-can-i-save-all-the-variables-in-the-current-python-session) – InfiniteFlash Sep 15 '19 at 00:28

1 Answers1

1

I am not familiar with r, but pickle offers functionality to save and load (variables, objects, types, etc...) in a pickle file. In this way you can save any details needed for a later session. I'm unsure if pickle offers a specific way to save all data associated with the current session or if you would be required to manually locate and save. Hope this helps!

import pickle 
my_obj = Object()
my_var = (1,"some_data")
filename = "my_dir\my_file.pickle"
with open(filename, ‘wb’) as f: #save data
    pickle.dump((my_obj, my_var), f)

with open(filename, ‘rb’) as f: #load data next time
    my_saved_obj, my_saved_var = pickle.load(f)
TheLazyScripter
  • 2,541
  • 1
  • 10
  • 19