Skip to content

Instantly share code, notes, and snippets.

@juwencheng
Created February 16, 2017 01:13
Show Gist options
  • Save juwencheng/ff9f05883f5bdfd71e834dd62a991a55 to your computer and use it in GitHub Desktop.
Save juwencheng/ff9f05883f5bdfd71e834dd62a991a55 to your computer and use it in GitHub Desktop.
通过Pickle保存和加载数据
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'}
@juwencheng
Copy link
Author

打开文件的时候使用with open() as f:可以不用关心文件的关闭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment