Created
December 30, 2013 04:02
-
-
Save studiawan/8177657 to your computer and use it in GitHub Desktop.
Object serialization using pickle
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
#!/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