File: pickle_test.py

package info (click to toggle)
pycxx 7.1.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,392 kB
  • sloc: cpp: 6,767; python: 1,138; sh: 85; ansic: 60; makefile: 18
file content (26 lines) | stat: -rw-r--r-- 564 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import simple
import copyreg
import pickle
import pprint

class can_be_pickled(simple.new_style_class):
    def __init__( self, value ):
        super().__init__()
        self.value = value

    def __reduce__( self ):
        return (simple.new_style_class, (self.value,))

#n = can_be_pickled( 'QQQZZZQQQ' )
n = simple.new_style_class( 'QQQZZZQQQ' )

print( 'n.value:', n.value )

print( 'pickle.dumps' )
s = pickle.dumps( n )
print( 'dumps:', repr(s) )

print( 'pickle.loads' )
n2 = pickle.loads( s )
print( 'loads:', repr(n2) )
print( 'n2.value:', n2.value )