Last active
August 29, 2015 14:14
-
-
Save masahiro-mi/0c8b810afa5ae8b2d9ab to your computer and use it in GitHub Desktop.
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
# To support the append (postscript) of the filewrite in pickle. | |
import pickle | |
# test data | |
data = ['this','is','a','test','.'] | |
appendix = ['this','is','appendix','.'] | |
def load_dumps(f): | |
obj = [] | |
while 1: | |
try: | |
obj.append(pickle.load(f)) | |
except: | |
break | |
return obj | |
if __name__ == '__main__': | |
print('raw data:\n'+str(data)) | |
# serialize | |
with open('pickle_test.dump', 'wb') as f: | |
pickle.dump(data, f) | |
# deserialize | |
with open('pickle_test.dump', 'rb') as f: | |
data = pickle.load(f) | |
print('pickle data:\n'+str(data)) | |
# try append | |
with open('pickle_test.dump', 'ab') as f: | |
pickle.dump(appendix, f) | |
# deserialize for appended dumps | |
with open('pickle_test.dump', 'rb') as f: | |
data = load_dumps(f) | |
print('appended pickle data:\n'+str(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment