This is my source code, I don't know why I'm getting the error.
I tried doing the code from the first, still it didn't work.
import pickle
def writeFile():
with open('main.dat', mode='rb+') as fh:
stu = {}
n = int(input('How many records you wanna enter(press 0 if no records to be added):'))
for i in range(n):
name = input('Enter the name of the student:')
roll = int(input('Enter the roll no of the student:'))
age = int(input('Enter the age of the student:'))
marks = int(input('Enter the marks of the student:'))
# updating record
stu['name'] = name
stu['age'] = age
stu['roll'] = roll
stu['marks'] = marks
# dumping in the file
updateRec = pickle.dump(stu, fh)
try:
view = True
while view:
data = pickle.load(fh)
print(data)
except Exception as err:
print(err)
writeFile()