Skip to content

Instantly share code, notes, and snippets.

@princewang1994
Last active November 8, 2018 08:27
Show Gist options
  • Save princewang1994/4dba0b5b62df3fe5018a605c94651c58 to your computer and use it in GitHub Desktop.
Save princewang1994/4dba0b5b62df3fe5018a605c94651c58 to your computer and use it in GitHub Desktop.
pickle存储和读取object
# 如果是python2需要用cpickle
import pickle
your_data = {'foo': 'bar'}
# Store data (serialize)
with open('filename.pickle', 'wb') as handle:
pickle.dump(your_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
# Load data (deserialize)
with open('filename.pickle', 'rb') as handle:
unserialized_data = pickle.load(handle)
print(your_data == unserialized_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment