English 中文(简体)
Strings & Serialization
  • 时间:2024-12-22

Strings and Seriapzation


Previous Page Next Page  

String seriapzation is the process of writing a state of object into a byte stream. In python, the “pickle” pbrary is used for enabpng seriapzation. This module includes a powerful algorithm for seriapzing and de-seriapzing a Python object structure. “Pickpng” is the process of converting Python object hierarchy into byte stream and “unpickpng” is the reverse procedure.

The demonstration of the pickle module is as follows −

import pickle

#Here s an example dict
grades = {  Apce : 89,  Bob : 72,  Charles : 87 }

#Use dumps to convert the object to a seriapzed string
serial_grades = pickle.dumps( grades )
print(serial_grades)

#Use loads to de-seriapze an object
received_grades = pickle.loads( serial_grades )
print(received_grades)

Output

The above program generates the following output −

Seriapzation Advertisements