Posted On: Feb 22, 2018
In Python Pickling is used for serializing objects in binary streams. Pickling can be performed on objects of data types like Booleans, Integers, Floats, Complex numbers, normal and Unicode Strings, Tuples, Lists, Sets, and Dictionaries.
UnPickling is reverse of the Pickling process, here binary streams have deserialized an object.
A simple example of Pickling and UnPickling In Python
import pickle // Pickling dogs_dict = { 'Ozzy': 3, 'Filou': 8, 'Luna': 5, 'Skippy': 10, 'Barco': 12, 'Balou': 9, 'Laika': 16 } filename = 'dogs' outfile = open(filename,'wb') pickle.dump(dogs_dict,outfile) outfile.close() // UnPickling infile = open(filename,'rb') new_dict = pickle.load(infile) infile.close()
Never Miss an Articles from us.
Java and Python differ in typing, syntax, and speed, but both are valuable for developers. Java uses static typing and braces for blocks, while Python uses dynamic typing and indentation. Python is ge..
Python’s try-except block allows for effective exception handling, enabling programmers to catch and handle errors without ending the program. This technique ensures that errors can be managed grace..
Python modules are ".py" files with classes, functions, and variables. Packages are directories containing modules and sub-packages, marked by an init.py file. This file can be empty but indicates the..