One minute
Save with Pickle
This is a short post to show an example on how to save (almost) any Python objects to a file using pickle
. Basically pickle
allows you to serialize/deserialize a Python object structure, which in turns allows you to save/load Python objects.
import pickle
my_object = {'hello': 'world'}
# Save
with open('filename.pkl', 'wb') as f:
pickle.dump(my_object, f, protocol=pickle.HIGHEST_PROTOCOL)
# Load
with open('filename.pickle', 'rb') as f:
my_object = pickle.load(f)
67 Words
2024-08-23 13:36