Pickle

pickle is a standard module of the python language. After installing python, the pickle library is already included and does not need to be installed separately. The pickle module implements basic data serialization and deserialization. Through the serialization operation of the pickle module, we can save the object information running in the program to a file and store it permanently; through the deserialization operation of the pickle module, we can create the object saved by the last program from the file.

The pickle module has two main types of interfaces, serialization and deserialization.
The serialization operations include:

  • pickle.dump()
  • Pickler(file, protocol).dump(obj)
    Deserialization operations include:
  • pickle.load()
  • Unpickler(file).load()

pickle.dump(obj, file, [,protocol])
  Note: Save the object obj to the file file.
     protocol is the protocol version used for serialization, 0: ASCII protocol, the serialized object is represented by printable ASCII code; 1: old-fashioned binary protocol; 2: the new binary protocol introduced in version 2.3, which is more efficient than the previous one. Among them, protocols 0 and 1 are compatible with older versions of python. The default value of protocol is 0.
     file: The file-like object to which the object is saved. file must have the write() interface, file can be a file opened with 'w' or a StringIO object or any other object that implements the write() interface. If protocol>=1, the file object needs to be opened in binary mode.
  pickle.load(file)
  annotation: read a string from file and reconstruct it into the original python object.
  file: a file-like object with read() and readline() interfaces.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326060581&siteId=291194637