I'm just trying out the pickle module and learning its functions and utilities. I've written this small piece of code, but it's giving me trouble.
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)
I then get the following error:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
pickle.load (myfile)
File "C:Python27libpickle.py", line 1378, in load
return Unpickler(file).load()
File "C:Python27libpickle.py", line 858, in load
dispatch[key](self)
KeyError: 'x00'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…