0% found this document useful (0 votes)
12 views

PYQs On Binary File Qs 23 March

The document discusses using Python to write and read binary files. It shows functions to write nested lists and dictionaries to binary files using pickle.dump() and read the data back using pickle.load(). One example filters the loaded data to only print items where the price is over 500.

Uploaded by

STARTED GAMING
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

PYQs On Binary File Qs 23 March

The document discusses using Python to write and read binary files. It shows functions to write nested lists and dictionaries to binary files using pickle.dump() and read the data back using pickle.load(). One example filters the loaded data to only print items where the price is over 500.

Uploaded by

STARTED GAMING
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Binary File PYQs

https://www.youtube.com/@TECHQueenLovejeetArora
Follow for more
Explanation of this Lecture Binary File PYQs
https://www.youtube.com/watch?v=ByIbaVHSxvM

import pickle
def Write():
File1=open("Sport.dat","wb")
NestedList=[]
while True:
SportName=input("Enter Sport Name")
TeamName=input("Enter Team Name")
No_Players=int(input("Enter No of Players"))
List=[SportName,TeamName,No_Players]
NestedList.append(List)
Ch=input("For More Enter y or Y")
if Ch not in "Yy":
break
pickle.dump(NestedList,File1)
File1.close()
#Write()
def CopyData():
File1=open("Sport.dat","rb")
File2=open("Basket.dat","wb")
Data=pickle.load(File1)
Count=0
for i in Data:
if i[0]=="BasketBall":
pickle.dump(i,File2)
Count+=1
return Count
#print("Total No of Copies",CopyData())
def Read():
File=open("Basket.dat","rb")
try:
while True:
Data=pickle.load(File)
print(Data)
except:
File.close()
Read()
Binary File PYQs
https://www.youtube.com/@TECHQueenLovejeetArora
Follow for more
Explanation of this Lecture Binary File PYQs
https://www.youtube.com/watch?v=ByIbaVHSxvM

import pickle
def Write():
File=open("BiFile.dat","wb")
Dict={}
while True:
MNO=int(input("Enter Movie No."))
MNAME=input("Movie Name")
MType=input("Movie")
Dict[MNO]=[MNAME,MType]
Ch=input("Enter More Y/y")
if Ch not in "Yy":
break
pickle.dump(Dict,File)
File.close()
def Read():
File=open("BiFile.dat","rb")
Data=pickle.load(File)
for i in Data:
print(Data[i][1])
#Write()
Read()
Binary File PYQs
https://www.youtube.com/@TECHQueenLovejeetArora
Follow for more
Explanation of this Lecture Binary File PYQs
https://www.youtube.com/watch?v=ByIbaVHSxvM
import pickle
def WriteRec():

File=open("BiFile.dat","wb")
#ID,Name,Price
while True:
ID=int(input("Enter ID"))
Name=input("Enter Name")
Price=int(input("Enter Price"))
List=[ID,Name,Price]
pickle.dump(List,File)
ch=input("Enter Y/y for Data -")
if ch not in "Yy":
break
File.close()
def ShowHigh():
File=open("BiFile.dat","rb")
try:
while True:
Data=pickle.load(File)
if Data[2]>500:
print(Data)
except:
File.close()
WriteRec()
ShowHigh()

You might also like