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

52

The document contains Python code for updating and deleting records in a file using the pickle module. It defines functions to update a record based on a player code and to delete a record by creating a new file without the specified record. Error handling is included to manage exceptions during file operations.
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)
5 views1 page

52

The document contains Python code for updating and deleting records in a file using the pickle module. It defines functions to update a record based on a player code and to delete a record by creating a new file without the specified record. Error handling is included to manage exceptions during file operations.
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

new = [pc,d1,d2,d3]

tf=1
f.seek(pos)
pickle.dump(new,f)

except Exception:
f.close()
if tf==0:
print("Record not found")
else:
print("Record Found and Updated..")

def bf_delete():
f = open('writer.dat','rb')
f1 = open('new.dat','wb')
pc = int(input('Player code to delete a record:'))
tf = 0
try:
while True:
data = pickle.load(f)
if data[0]!=pc:
pickle.dump(data,f1)
else:
tf=1
except Exception:
f.close()
f1.close()
os.remove('writer.dat')
os.rename('new.dat','writer.dat')
if tf==:
print("Record not found..")
else:
print("Record Found and Deleted..")

52

You might also like