You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
467 B

  1. from __future__ import print_function
  2. import sys
  3. sys.path.append('.')
  4. from example import Pickleable
  5. try:
  6. import cPickle as pickle # Use cPickle on Python 2.7
  7. except ImportError:
  8. import pickle
  9. p = Pickleable("test_value")
  10. p.setExtra1(15)
  11. p.setExtra2(48)
  12. data = pickle.dumps(p, 2) # Must use pickle protocol >= 2
  13. print("%s %i %i" % (p.value(), p.extra1(), p.extra2()))
  14. p2 = pickle.loads(data)
  15. print("%s %i %i" % (p2.value(), p2.extra1(), p2.extra2()))