Created
December 12, 2019 15:35
-
-
Save nimpy/142d5b3f0c4544f4d9dc160776bf26bf to your computer and use it in GitHub Desktop.
Template for pickling and unpickling variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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