Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created January 9, 2013 20:45
Show Gist options
  • Save farhaven/4496768 to your computer and use it in GitHub Desktop.
Save farhaven/4496768 to your computer and use it in GitHub Desktop.
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