Binary file operations with pickle PYQ part 3
PYQ PRACTICE SCOPE: Binary file operations with pickle.
Concept ID: U1_BINARY_PICKLE_OPS.
Use only previous-year questions whose concept_ids include U1_BINARY_PICKLE_OPS.
Key things we'll cover
Binary file operations with pickle
PYQ references used by both prompts7 included0 excluded
Flagged questions are excluded from both Study Notes and PPT references until corrected in Paper Analyzer.
Included
ID 6495 · 2021 · 1 mark(s)
Which of the following statement opens a binary file record.bin in write mode and writes data from a list lst1 = [1,2,3,4] on the binary file?
a) with open('record.bin','wb') as myfile:
pickle.dump(lst1,myfile)
b) with open('record.bin','wb') as myfile:
pickle.dump(myfile,lst1)
c) with open('record.bin','wb+') as myfile:
pickle.dump(myfile,lst1)
d) with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included
ID 6526 · 2021 · 1 mark(s)
Choose the function name that should be used in the blank space of line marked as Statement-6 to create the desired CSV File.
(Refer to the CSV file creation code in the case study: stuwriter._____(data))
a) dump()
b) load()
c) writerows()
d) writerow()
File Handling → CSV file read write and search, Binary file operations with pickle
Included
ID 6566 · 2022 · 5 mark(s)
Give any one point of difference between a binary file and a csv file.
Write a Program in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of an employee to a CSV file 'furdata.csv'. Each record consists of a list with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.
(ii) search() – To display the records of the furniture whose price is more than 10000.
File Handling → CSV file read write and search, Binary file operations with pickle
Included
ID 6607 · 2023 · 5 mark(s)
(i) Differentiate between r+ and w+ file modes in Python.
(ii) Consider a file, SPORT.DAT, containing records of the following structure:
[SportName, TeamName, No_Players]
Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the records with Sport name as "Basket Ball" to the file named BASKET.DAT. The function should return the total number of records copied to the file BASKET.DAT.
(ii) A Binary file, CINEMA.DAT has the following structure:
{MNO:[MNAME, MTYPE]}
Where MNO – Movie Number, MNAME – Movie Name, MTYPE is Movie Type.
Write a user defined function, findType(mtype), that accepts mtype as parameter and displays all the records from the binary file CINEMA.DAT, that have the value of Movie Type as mtype.
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included
ID 6365 · 2024 · 5 mark(s)
(a) (i) What is the main purpose of seek() and tell() method ?
(ii) Consider a binary file, Cinema.dat containing information in the following structure :
[Mno, Mname, Mtype]
Write a function, search_copy(), that reads the content from the file Cinema.dat and copies all the details of the "Comedy" movie type to file named movie.dat.
(ii) A Binary file, "Items.dat" has the following structure :
[Icode, Description, Price]
Where
Icode – Item code
Description – Detail of item
Price – Price of item
Write a function Add_data(), that takes Icode, Description and Price from the user and writes the information in the binary file "Items.dat".
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included
ID 6192 · 2025 · 1 mark(s)
Assertion (A): For a binary file opened using 'rb' mode, the pickle.dump() method will display an error.
Reason (R): The pickle.dump() method is used to read from a binary file.
(A) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).
(B) Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A).
(C) Assertion (A) is true but Reason (R) is false.
(D) Assertion (A) is false but Reason (R) is true.
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included
ID 6227 · 2026 · 1 mark(s)
Consider the statement given below :
f1 = open("pqr.dat","_______")
Which of the following is the correct file mode to open the file in read only mode ?
(A) a
(B) rb
(C) r+
(D) rb+
File Handling → File basics paths modes seek and tell, Binary file operations with pickle