0

i want to ask why we should pickle an object in python ?
why the file that we want to pickle should be opened in binary mode ?
and what is the HIGHEST_PROTOCOL used in pickling ?

CDspace
  • 2,639
  • 18
  • 30
  • 36
D.AhmedRafik
  • 81
  • 2
  • 15

1 Answers1

4
  1. You don't "have to" pickle an object, but in case you want to (for purpose of saving it, sending it etc) you can use pickling (serializing).
  2. from the docs:

Note: Be sure to always open pickle files created with protocols >= 1 in binary mode. ...

it means that only files that weren't created using ASCII protocol (protocol 0) should be opened in binary mode. As for why - the answer is probably in the implementation of pickling.

  • HIGHEST_PROTOCOL is another way of naming the "latest" protocol
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129