w3ajay

tally tutorial point, ms word 2013, ms excel 2013, ms powerpoint 2010,ccc question with answer in hindi 2021, Tally Prime in hindi , tally prime,Python,in python,programming in python,python

Thursday, August 1, 2024

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

 


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.'''





Function  in python to copy records from on binary file to another file 

'''(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.'''



import pickle
def copyData():
    f=open("SPORT.DAT","rb")
    count=0
    data=pickle.load(f)
    a=[]
    for i in data:
        if i[0]=='Basket Ball':
            a.append(i)
            count+=1
    fobj=open("BASKET.DAT","wb")
    pickle.dump(a,fobj)
    
    

    f.close()
    fobj.close()
    return count
copyData()
            


Please share like and comment




No comments:

Post a Comment

for more information please share like comment and subscribe