Which of the following methods is used to unpickling data from a binary file?
Which of the following methods is used to unpickling data from a binary file?
Solution
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).
Related questions:
2026: 19 May Shift 1
2026: 23 May Shift 1
2026: 18 May Shift 2
2026: 21 May Shift 1