Serializing Objects
• Serialize an object: convert the object to a stream of
bytes that can easily be stored in a file
• Pickling: serializing an object
• To pickle an object:
• Import the pickle module
• Open a file for binary writing
• Call the pickle.dump function
• Format: pickle.dump(object, file)
• Close the file
• You can pickle multiple objects to one file prior to closing the file
• Unpickling: retrieving pickled object
• To unpickle an object:
• Import the pickle module
• Open a file for binary writing
• Call the pickle.load function
• Format: pickle.load(file)
• Close the file
• You can unpickle multiple objects from the file