Which method out of the following will allow the read operation from a Binary…
2023
Which method out of the following will allow the read operation from a Binary file in a Python program?
- A.
read
- B.
input
- C.
accept
- D.
load
Attempted by 941 students.
Show answer & explanation
Correct answer: D
Concept
In the NCERT / CBSE Class 12 Computer Science course, binary files are handled with the pickle module. Serialisation is done with pickle.dump() to write an object to a binary file, and pickle.load() to read (de-serialise) an object back. In this curriculum the data is not 'read' but loaded, and not 'written' but dumped.
Application
To read from a binary file, the file is opened in binary-read mode and the object is retrieved with the load() method of the pickle module:
Import the module:
import pickle.Open the file in binary-read mode:
f = open('data.dat', 'rb').Read the stored object:
obj = pickle.load(f)— this returns the original Python object.
Cross-check / Contrast
inputtakes a line typed at the keyboard (standard input) and returns a string — it never touches a file.acceptis not a Python file-handling method at all; no such built-in exists for files.readis the generic byte-stream method on a file object; while a file opened in'rb'technically supports it, the NCERT binary-file convention pairs reading specifically withload(), which mirrorsdump().