Merge pull request #9 from paulscherrerinstitute/JakHolzer-pickle_dump

simple pickle function to store the dict
This commit is contained in:
usov_i 2020-09-11 11:10:20 +02:00 committed by GitHub
commit 9412de17da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,19 @@
import pickle
def save_dict(obj, name):
""" saves dictionary as pickle file in binary format
:arg obj - object to save
:arg name - name of the file
NOTE: path should be added later"""
with open(name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_dict(name):
"""load dictionary from picle file
:arg name - name of the file to load
NOTE: expect the file in the same folder, path should be added later
:return dictionary"""
with open(name + '.pkl', 'rb') as f:
return pickle.load(f)