Last active
November 8, 2018 08:27
-
-
Save princewang1994/4dba0b5b62df3fe5018a605c94651c58 to your computer and use it in GitHub Desktop.
pickle存储和读取object
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
# 如果是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