Created
February 16, 2017 01:13
-
-
Save juwencheng/ff9f05883f5bdfd71e834dd62a991a55 to your computer and use it in GitHub Desktop.
通过Pickle保存和加载数据
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 | |
# save object to pickle | |
file = open('data.pickle', 'wb') # `b` abbr of binary | |
pickle.dump({'key':'value'}, file) | |
file.close() | |
# load object from pickle | |
file = open('data.pickle', 'rb') | |
dict = pickle.load(file) | |
file.close() | |
print(dict) | |
# output is {'key':'value'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
打开文件的时候使用with open() as f:可以不用关心文件的关闭