Skip to main contentSkip to solution

Which of the following methods is used to unpickling data from a binary file?

Solution

✅ Correct Option: 2

pickle.load(fileobject) reads pickled (serialised) data from a file opened in binary read mode ("rb") and converts it back into the original Python object. This process is called unpickling.

Example: data = pickle.load(f), where f = open("file.dat", "rb").


Options 1, 3 and 4: seek(), read() and readlines() are methods of file objects, not of the pickle module, and the pickle module has no such functions. Reading with read() or readlines() on a file object returns raw bytes or lines, not the restored object.

The matching function for pickling is pickle.dump(obj, fileobject).

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question