Cannot load pickled object

前端 未结 2 2014
花落未央
花落未央 2021-02-02 04:50

The problem I am having is when I try to load the pickled object. I have tried using both pickle.loads and pickle.load Here are the re

2条回答
  •  没有蜡笔的小新
    2021-02-02 05:46

    You need to either read the file first (as binary bytes) and use pickle.loads(), or pass an open file object to the pickle.load() command. The latter is preferable:

    with open('out/cache/' +hashed_url, 'rb') as pickle_file:
        content = pickle.load(pickle_file)
    

    Neither method supports loading a pickle from a filename.

提交回复
热议问题