Skip to content

Instantly share code, notes, and snippets.

@un33k
Created October 24, 2011 13:34
Show Gist options
  • Select an option

  • Save un33k/1309039 to your computer and use it in GitHub Desktop.

Select an option

Save un33k/1309039 to your computer and use it in GitHub Desktop.
simple serialization of a python object
try:
import cPickle as pickle
except:
import pickle
import pprint
data1 = [ { 'a':'A', 'b':2, 'c':3.0 } ]
print 'BEFORE:',
pprint.pprint(data1)
data1_string = pickle.dumps(data1)
data2 = pickle.loads(data1_string)
print 'AFTER:',
pprint.pprint(data2)
print 'SAME?:', (data1 is data2)
print 'EQUAL?:', (data1 == data2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment