example15.py 485 Bytes
Newer Older
Wenzel Jakob's avatar
Wenzel Jakob committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from __future__ import print_function
import sys

sys.path.append('.')

from example import Pickleable

try:
    import cPickle as pickle  # Use cPickle on Python 2.7
except ImportError:
    import pickle

p = Pickleable("test_value")
p.setExtra1(15)
p.setExtra2(48)

data = pickle.dumps(p, -1)  # -1 is important (use highest protocol version)
print("%s %i %i" % (p.value(), p.extra1(), p.extra2()))

p2 = pickle.loads(data)
print("%s %i %i" % (p2.value(), p2.extra1(), p2.extra2()))