0% found this document useful (0 votes)
21 views1 page

Updating Binary File Content

Uploaded by

rufussamuel29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Updating Binary File Content

Uploaded by

rufussamuel29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import pickle

def createFile():
f=open("Book.dat","wb")
record=[]
ch='Y'
while ch=='Y' or ch=='y':
BookName=input("Name :")
Author = input("Author:" )
Price = int(input("Price : "))
rec=[BookName,Author,Price]
record.append(rec)
ch=input("Do you want to add more records....?Enter(Y/N) : ")
pickle.dump(record,f)
f.close()
print("File is saved.")
#update
f=open("Book.dat","rb")
x=pickle.load(f)

y=input("Enter the Name of Book you want to update the price:")


for i in x:
if i[0]==y:
print("Price of the book:",i[2])
p=int(input("Enter the new price:"))
i[2]=p
print("The record after updation is:",i)
print("The content of the file is:",x)

createFile()

You might also like