Skip to content

Instantly share code, notes, and snippets.

@nimpy
Created December 12, 2019 15:35
Show Gist options
  • Save nimpy/142d5b3f0c4544f4d9dc160776bf26bf to your computer and use it in GitHub Desktop.
Save nimpy/142d5b3f0c4544f4d9dc160776bf26bf to your computer and use it in GitHub Desktop.
Template for pickling and unpickling variables
import pickle
import datetime
def pickle_vars(var1, var2):
pickle_file_path = 'zimnica/pickled_vars_' + datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + '.pickle'
try:
pickle.dump((var1, var2), open(pickle_file_path, "wb"))
except Exception as e:
print("Problem while trying to pickle: ", str(e))
def unpickle_vars(pickle_file_path):
try:
var1, var2 = pickle.load(open(pickle_file_path, "rb"))
return var1, var2
except Exception as e:
print("Problem while trying to unpickle: ", str(e))
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment