Created
January 9, 2013 20:45
-
-
Save farhaven/4496768 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class Test(object): | |
def __init__(self, idx): | |
self.foo = 100 * idx | |
self.bar = 200 * idx | |
if __name__ == "__main__": | |
l = [] | |
for x in range(20): | |
l.append(Test(x)) | |
print("Before pickling:") | |
print(str(l)) | |
fh = open("/tmp/objects", "w") | |
pickle.dump(l, fh) | |
fh.close() | |
fh = open("/tmp/objects", "r") | |
x = pickle.load(fh) | |
fh.close() | |
print("Unpickled:") | |
print(str(x)) | |
print(x[1].foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment