I am creating a program that manages a file for patients; it's part of a project. I've created a log file. I've pickled the information of the patients as instances in the file. In the following code, I'm attempting to traverse the file and receive the patient instance that satisfies the given condition:
def searchpatientnumber():
patobj=open("G:\patientregister.log", "ab+")
test=patient() #the patient class
patientid=raw_input("Enter patient register number:")
import pickle
test=pickle.load(patobj)
try:
while True: #I hoped that this loop will help read the whole file
if test.registerno==patientid: #registerno is a datamember
test.displaynumber() #member function
break
else:
print "Patient not registered, try again."
break
except EOFError:
patobj.close()
The code works, however, it is only able to read the first instance in the file but can't read the rest. Can I please get a way to traverse all the instances of a binary file? Thank you.