Created
January 25, 2017 07:14
-
-
Save zhanglongqi/542042313880ed4b166befd74d3ff86e to your computer and use it in GitHub Desktop.
Pickle example of 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
import pickle | |
data1 = {'foo': [1, 2, 3], | |
'bar': ('Hello', 'world!'), | |
'baz': True} | |
# write the pickled data to the file jar | |
with open('data.pkl', mode='wb') as jar: | |
pickle.dump(data1, jar, fix_imports=True) | |
# load it into a variable | |
with open('data.pkl', mode='rb') as pkl_file: | |
data2 = pickle.load(pkl_file) | |
print(data2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment