Created
March 24, 2020 13:20
-
-
Save z-------------/a966a7480976be4a8c23edebbd97d50f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def pickle_load(filename): | |
| return pickle.load(open(filename, "rb")) | |
| def pickle_dump(data, filename): | |
| return pickle.dump(data, open(filename, "wb")) | |
| def pickle_get(filename, fn, *args, fresh=False, verbose=False): | |
| """Try to load data from a pickle file. Compute it with `fn` and save it if it doesn't exist.""" | |
| if not fresh and file_exists(filename): | |
| if verbose: | |
| print("using pickled save from %s." % filename) | |
| return pickle_load(filename) | |
| else: | |
| if verbose: | |
| print("computing data...") | |
| data = fn(*args) | |
| pickle_dump(data, filename) | |
| if verbose: | |
| print("wrote to %s." % filename) | |
| return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment