What is pickle in python? In which scenarios can this feature of python come handy? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is pickle in python? In which scenarios can this feature of python come handy?

23rd Jul 2017, 6:49 AM
Shishir Shetty
Shishir Shetty - avatar
3 Answers
+ 1
mostly, pickle used for serializing and de-serializing. by that I mean converting an object to byte stream and vice versa. but the easiest way you can use it is in a scenario where you want to store a python object like dict or list in a file and restore it. for this purpose you can open a file as binary and dump the object to file. fo restore the object you just need to use load method of pickle library. very easy and handy.
25th Jul 2017, 4:26 AM
Srn Mrf
Srn Mrf - avatar
+ 1
@ Srn mrf ...so should the file always be binary?
25th Jul 2017, 1:31 PM
Shishir Shetty
Shishir Shetty - avatar
+ 1
afaik yes. it should. bw mode for dumping object to file and rw mode to restore it from file.
25th Jul 2017, 8:52 PM
Srn Mrf
Srn Mrf - avatar