Test Index

CBSE Class 12 Computer Science 2026 Paper Compartment Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 11 of 37
Marks: +1, -0
Which of the following options is the correct mode to open a binary pickled file to add more data in a previously existing binary pickled file ?
Solution:  
Concept:
Pickled files are binary files, so the mode needs b. To add data at the end of an existing file without erasing it, the mode is append (a).
Explanation:
'ab' = append + binary: the file pointer is at the end and old records are kept.
import pickle
with open('data.dat', 'ab') as f:
pickle.dump(rec, f)
'rb' and 'r' only read; 'w' is a text mode that also erases the existing contents.
Answer:
Option B ('ab')
© examsnet.com
Advertisements
Go to Question: