pickle


1) What are Pickling and Unpickling?
Pickling: The pickle module converts any Python object into a byte stream (not a string representation). This byte stream can then be stored in a file, sent over a network, or saved for later use. The function used for pickling is pickle.dump().
Unpickling: The process of retrieving the original Python object from the byte stream (saved during pickling) is called unpickling. The function used for unpickling is pickle.load().


import pickle 

data = {"a": 1, "b": 2}

with open("data.pkl", "wb") as f:
    pickle.dump(data, f)



import pickle 

with open("data.pkl", "rb") as f:
    data = pickle.load(f)

print(data)




© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext