相关疑难解决方法(0)

为什么我会读取"Pickle - EOFError:Ran out of input"读取空文件?

我在尝试使用时遇到了一个有趣的错误Unpickler.load(),这里是源代码:

open(target, 'a').close()
scores = {};
with open(target, "rb") as file:
    unpickler = pickle.Unpickler(file);
    scores = unpickler.load();
    if not isinstance(scores, dict):
        scores = {};
Run Code Online (Sandbox Code Playgroud)

这是追溯:

Traceback (most recent call last):
File "G:\python\pendu\user_test.py", line 3, in <module>:
    save_user_points("Magix", 30);
File "G:\python\pendu\user.py", line 22, in save_user_points:
    scores = unpickler.load();
EOFError: Ran out of input
Run Code Online (Sandbox Code Playgroud)

我想读的文件是空的.如何避免出现此错误,并获取空变量?

python file pickle

79
推荐指数
5
解决办法
13万
查看次数

标签 统计

file ×1

pickle ×1

python ×1