什么是'无效加载键,'\x00

-1 投票
0 回答
21 浏览
提问于 2025-04-11 22:45

这是我的源代码,我不知道为什么会出现这个错误。

我从头开始写代码,但还是不行。

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()

0 个回答

暂无回答

撰写回答