我只是嘗試了泡菜模塊和學習它的功能和實用程序。我寫了一小段代碼,但它給我帶來麻煩。無法從文件加載pickle對象
import pickle
myfile = open("C:\\Users\\The Folder\\databin.txt", 'r+') #databin.txt is completely blank
class A:
def __init__ (self):
self.variable = 25
self.random = 55
pickle.dump (A, myfile, -1) #HIGHEST_PROTOCOL
pickle.load (myfile)
然後我得到以下錯誤:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
pickle.load (myfile)
File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
KeyError: '\x00'
你的代碼沒有意義,你可以只醃對象的實例,但不能直接調用類。 – 2012-08-12 08:47:48