pickle problem:cant reload object saved with binary option
Marshall
python at scoobysnacks.com
Sat Jan 1 11:04:08 EST 2000
I created a class instance (self.info) to hold all my variables and
I'm trying to save it for use in later sessions. The binary file is
much smaller but if I set the binary flag while saving, it blows an
error when I try to load it. I'm trying this on Win98 and I'm calling
it from a Menu widget using command=self.save and I change the default
bin=0 to bin=1 and it won't load anymore. The load error is at the
bottom. Any direction is greatly appreciated. Thanks.
The documentation says ...
The Unpickler class does not have an argument to distinguish between
binary and text pickle formats; it accepts either format.
def save(self,file='test.sav',bin=0):
blah=open(file,'w')
pickle.dump(self.info,blah,bin)
blah.close()
def load(self,file='test.sav'):
blah=open(file,'r')
self.info=pickle.load(blah)
blah.close()
self.buildlist()
Exception in Tkinter callback
Traceback (innermost last):
File "C:\Program Files\Python\Lib\lib-tk\Tkinter.py", line 764, in
__call__
return apply(self.func, args)
File "new.py", line 249, in load
self.info=pickle.load(blah)
File "C:\Program Files\Python\Lib\pickle.py", line 826, in load
return Unpickler(file).load()
File "C:\Program Files\Python\Lib\pickle.py", line 495, in load
dispatch[key](self)
File "C:\Program Files\Python\Lib\pickle.py", line 509, in load_eof
raise EOFError
EOFError:
P.S. python at scoobysnacks.com is valid email
More information about the Python-list
mailing list