pickle problem:cant reload object saved with binary option

Marshall python at scoobysnacks.com
Sat Jan 1 13:06:06 EST 2000


Thanks, now I have a new problem.  It still works without the binary
option.  I think I have the organization of my data screwed up
somehow, but I don't understand why it works without the binary, and
breaks if I turn it on.  It doesn't matter if I use pickle or cPickle,
I still get errors.  The object I'm pickling is self.info=crccvars()
Thanks in advance for any insight.

	def save(self,file='crcc.sav'):
		blah=open(file,'w')
		cPickle.dump(self.info,blah,1)
		blah.close()
	def load(self,file='crcc.sav'):
		print 'print self     :',self
		print 'print __name__ :',__name__
		print 'print self.info:',self.info
		print ''
		blah=open(file,'r+b')
		self.info=cPickle.load(blah)
		blah.close()
		self.buildlist()

each time I open the app, save, then load and here's what I get ...

print self     : <__main__.crcc instance at 7b3830>
print __name__ : __main__
print self.info: <__main__.crccvars instance at 7b6df0>

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 250, in load
    self.info=cPickle.load(blah)
ImportError: No module named __main__



On Sat, 1 Jan 2000 11:15:15 -0500, "Darrell" <news at dorb.com> wrote:

>Try this:
>        fp=open(fn,'r+b')
>
>
>--
>--Darrell
>"Marshall" <python at scoobysnacks.com> wrote in message
>news:386e1de1.998928692 at news-server...
>> 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.
>>
>
>
>




More information about the Python-list mailing list