# Object serialization
Import Pickle
D = { " A " : " China " }
A = pickle. dumps (D, 2) # Serialize binary
Print A
F = open (" Data " , " WB " )
F. Write ()
F. Close ()
# Object deserialization
Import Pickle
F = open ( " Data " ," RB " )
A = f. Read ()
D = pickle. Loads ()
Print D [ ' A ' ]
The value range of pickle. dumps (D, 2) is (0, 1, 2), and 2 is binary.
Note:
What if we serialize A Class Object (class instance? An object can be instantiated on machine A and can be correctly serialized and transmitted. An error occurs when deserialization is reached on machine B, the prompt is that the class of this object is not instantiated, but this class is defined at this time, the deserialization can be successful, and there is no problem with method calling. That is to say, during serialization, the object metadata is entered into the package, but an error occurs when the metadata cannot be found on machine B.
conclusion: If A and B have the same Lib, the class defined in this lib, their objects can be transferred and used across machines