Advertisements
Advertisements
प्रश्न
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.
टीपा लिहा
Advertisements
उत्तर
def copyData():
fObj = open("SPORT.DAT", "rb")
fObj1 = open ("BASKET.DAT", "wb")
cnt=0
try:
while True:
data = pickle.load(fObj)
print (data)
if data[0] == "Basket Ball":
pickle.dump (data, fObj1)
cnt+=1
except:
fObj.close()
fObj1.close()
return cntshaalaa.com
The Pickle Module in Python
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
