📅  最后修改于: 2020-11-07 09:11:20             🧑  作者: Mango
字符串序列化是将对象的状态写入字节流的过程。在Python,“ pickle”库用于启用序列化。该模块包括用于对Python对象结构进行序列化和反序列化的强大算法。 “ Pickling”是将Python对象层次结构转换为字节流的过程,而“ unpickling”是相反的过程。
泡菜模块的演示如下-
import pickle
#Here's an example dict
grades = { 'Alice': 89, 'Bob': 72, 'Charles': 87 }
#Use dumps to convert the object to a serialized string
serial_grades = pickle.dumps( grades )
print(serial_grades)
#Use loads to de-serialize an object
received_grades = pickle.loads( serial_grades )
print(received_grades)
上面的程序生成以下输出-