Why do I get “Pickle - EOFError: Ran out of input” reading an empty file?

前端 未结 7 2469
小鲜肉
小鲜肉 2020-11-28 05:55

I am getting an interesting error while trying to use Unpickler.load(), here is the source code:

open(target, \'a\').close()
scores = {};
with o         


        
7条回答
  •  孤街浪徒
    2020-11-28 06:36

    It is very likely that the pickled file is empty.

    It is surprisingly easy to overwrite a pickle file if you're copying and pasting code.

    For example the following writes a pickle file:

    pickle.dump(df,open('df.p','wb'))
    

    And if you copied this code to reopen it, but forgot to change 'wb' to 'rb' then you would overwrite the file:

    df=pickle.load(open('df.p','wb'))
    

    The correct syntax is

    df=pickle.load(open('df.p','rb'))
    

提交回复
热议问题