Created
July 3, 2018 09:43
-
-
Save umeshnrao/96992986ba7e56ba114fe0949ad23237 to your computer and use it in GitHub Desktop.
Python
This file contains hidden or 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
# Pickling | |
import pickle | |
# An arbitrary collection of objects supported by pickle. | |
data = { | |
'a': [1, 2.0, 3, 4+6j], | |
'b': ("character string", b"byte string"), | |
'c': {None, True, False} | |
} | |
with open('data.pickle', 'wb') as f: | |
# Pickle the 'data' dictionary using the highest protocol available. | |
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL) | |
with open('data.pickle', 'rb') as f: | |
# The protocol version used is detected automatically, so we do not | |
# have to specify it. | |
data = pickle.load(f) | |
########################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment