Skip to content

Instantly share code, notes, and snippets.

@studiawan
Created December 30, 2013 04:02
Show Gist options
  • Save studiawan/8177657 to your computer and use it in GitHub Desktop.
Save studiawan/8177657 to your computer and use it in GitHub Desktop.
Object serialization using pickle
#!/usr/bin/env python
import pickle
# declare a list
mylist = []
# assigning value to list
mylist.append('This is string') # string
mylist.append(5) # integer
mylist.append(('localhost', 5000)) # tuple
# print list
print "----- This is original list: -----\n"
print mylist, "\n\n"
# pickle object (in this example, the object is a list)
p = pickle.dumps(mylist)
# print pickled object
print "----- This is pickled list: -----\n"
print p, "\n\n"
# unpickle object
u = pickle.loads(p)
# print unpickled object
print "----- This is unpickled list: -----\n"
print u, "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment