Skip to content

Instantly share code, notes, and snippets.

@manukalia
Last active June 20, 2021 10:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manukalia/3f422fd8966c42e35b145f62dbb1005b to your computer and use it in GitHub Desktop.
Save manukalia/3f422fd8966c42e35b145f62dbb1005b to your computer and use it in GitHub Desktop.
Pickle Dump and Pickle Load Syntax and Example
import pickle
# TO SAVE ANY OBJECT (source_object_name) AS A PICKLE FILE...
with open('../directory_name/source_object_name.pkl', 'wb') as f:
pickle.dump(object_name, f)
# TO UPLOAD ANY PICKLE FILE INTO AN OBJECT (dest_object_name)...
with open('../directory_name/source_object_name.pkl', 'rb') as f:
dest_object_name = pickle.load(f)
@manukalia
Copy link
Author

manukalia commented Jun 22, 2019

This is a pair of complementary implementations of "pickle".

The pickle-dump snippet is how to "save" any python object (i.e. avariable, dataframe, fitted
model, etc.) into a serialized binary file.

The pickle_load snippet is the opposite... the way to load a pickled file back into memory
and to make use of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment