Skip to content

Instantly share code, notes, and snippets.

@Merwanski
Created January 21, 2023 20:47
Show Gist options
  • Save Merwanski/91f23b152941e93e54ebef948239e4c8 to your computer and use it in GitHub Desktop.
Save Merwanski/91f23b152941e93e54ebef948239e4c8 to your computer and use it in GitHub Desktop.
write_read_pickle.py
################################################################################
## 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