我的代碼有問題,在這種情況下,unpickling每次都會導致「Ran out of input」錯誤。爲了測試這個,我在命令提示符下運行了一個小東西pickle「用完輸入」在一個文件上醃製
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open('C:/Users/Administrator/Desktop/testing/playerlist.txt', 'wb') as f:
... pickle.dump({"foo": "bar"}, f)
...
>>> with open('C:/Users/Administrator/Desktop/testing/playerlist.txt', 'rb') as f:
... print(f.read())
... print(pickle.loads(f.read()))
...
b'\x80\x03}q\x00X\x03\x00\x00\x00fooq\x01X\x03\x00\x00\x00barq\x02s.'
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
EOFError: Ran out of input
>>>
這段代碼之前爲我工作,但突然沒有。我誤解了一些鹹菜嗎?