- Python Design Patterns - Home
- Introduction
- Python Design Patterns - Gist
- Model View Controller Pattern
- Python Design Patterns - Singleton
- Python Design Patterns - Factory
- Python Design Patterns - Builder
- Python Design Patterns - Prototype
- Python Design Patterns - Facade
- Python Design Patterns - Command
- Python Design Patterns - Adapter
- Python Design Patterns - Decorator
- Python Design Patterns - Proxy
- Chain of Responsibility Pattern
- Python Design Patterns - Observer
- Python Design Patterns - State
- Python Design Patterns - Strategy
- Python Design Patterns - Template
- Python Design Patterns - Flyweight
- Abstract Factory
- Object Oriented
- Object Oriented Concepts Implementation
- Python Design Patterns - Iterator
- Dictionaries
- Lists Data Structure
- Python Design Patterns - Sets
- Python Design Patterns - Queues
- Strings & Serialization
- Concurrency in Python
- Python Design Patterns - Anti
- Exception Handling
Strings and Serialization
String serialization is the process of writing a state of object into a byte stream. In python, the pickle library is used for enabling serialization. This module includes a powerful algorithm for serializing and de-serializing a Python object structure. Pickling is the process of converting Python object hierarchy into byte stream and unpickling is the reverse procedure.
The demonstration of the pickle module is as follows −
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)
Output
The above program generates the following output −
Advertisements