Python pickle/unpickle a list to/from a file

前端 未结 2 1755
我在风中等你
我在风中等你 2020-12-11 14:43

I have a list that looks like this:

a = [[\'a string\', [0, 0, 0], [22, \'bee sting\']], [\'see string\', 
    [0, 2, 0], [22, \'d string\']]]
2条回答
  •  醉梦人生
    2020-12-11 15:33

    Decided to make it as an answer. pickle.load method expects to get a file like object, but you are providing a string instead, and therefore an exception. So instead of:

    pickle.load('afile')
    

    you should do:

    pickle.load(open('afile', 'rb'))
    

提交回复
热议问题