Last active
June 20, 2021 10:02
-
-
Save manukalia/3f422fd8966c42e35b145f62dbb1005b to your computer and use it in GitHub Desktop.
Pickle Dump and Pickle Load Syntax and Example
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 | |
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.