pickle problem:cant reload object saved with binary option
Darrell
news at dorb.com
Sat Jan 1 13:50:01 EST 2000
import cPickle
class X:
def __init__(self):
self._x=1
self._y=2
def save(self,file='crcc.sav'):
blah=open(file,'w+b')
cPickle.dump(self,blah,1)
blah.close()
def load(self,file='crcc.sav'):
blah=open(file,'r+b')
val=cPickle.load(blah)
blah.close()
return val
x=X()
x._x=111111
x._z=333333
x.save()
x1=X()
x1=x1.load()
for n in x1.__dict__.keys():
print n,'=', getattr(x1,n)
######################## Output
_x = 111111
_y = 2
_z = 333333
Replaced all tabs with spaces so this code should survive the mail.
--
--Darrell
"Marshall" <python at scoobysnacks.com> wrote in message
news:386e31c2.1004019140 at news-server...
> Thanks, now I have a new problem. It still works without the binary
> option.
More information about the Python-list
mailing list