Created
January 21, 2023 20:47
-
-
Save Merwanski/91f23b152941e93e54ebef948239e4c8 to your computer and use it in GitHub Desktop.
write_read_pickle.py
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
################################################################################ | |
## WRITE PICKLE | |
#!/usr/bin/env python | |
import pickle | |
import numpy as np | |
a = np.matrix('1 2; 3 4') | |
b = 0 | |
c = 'text' | |
# Saving the objects: | |
with open('data.pkl', 'w') as f: # Python 3: open(..., 'wb') | |
pickle.dump([a, b, c], f) | |
################################################################################ | |
## READ PICKLE | |
#!/usr/bin/env python | |
import pickle | |
import numpy as np | |
# Getting back the objects: | |
with open('data.pkl') as f: # Python 3: open(..., 'rb') | |
a, b, c = pickle.load(f) | |
print(a) | |
print(b) | |
print(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment