<div>hello, </div> <div> </div> <div>I have a question about the pickler. I'm using it to save objects in a program of mine that I can later reload to use. I was wondering how the pickle works and how it references the class module when I unpickle the pickled objects. for example I save some objects using the pickler, then I continue to develop my program so the class module is changed and additional attributes and methods are added. What happens now when I unpickle the pickled data and try to operate on it using the new methods and new attributes?</div> <div> </div> <div>here's an example if I didn't explain myself well...</div> <div> </div> <div>I create a class of data called 'var'</div> <div> </div> <div>class var:</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div>def __init__(self):</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div>self.data = numpy.array([1,2,3,4])</div> <div>self.color = 'blue'</div></BLOCKQUOTE>
<div dir=ltr> </div> <div dir=ltr>def operate(self):</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div dir=ltr>return self.data+1</div></BLOCKQUOTE></BLOCKQUOTE> <div dir=ltr> </div> <div dir=ltr>now create the instance: </div> <div dir=ltr>myVariable = var()</div> <div dir=ltr>I then pickle it to some file. and now I continue to develop my class module:</div> <div dir=ltr> </div> <div>class var:</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div>def __init__(self):</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div>self.data = numpy.array([1,2,3,4])</div> <div>self.color = 'blue'</div> <div>self.name = 'bob'</div></BLOCKQUOTE> <div dir=ltr> </div> <div dir=ltr>def operate(self):</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div dir=ltr>return self.data+1</div></BLOCKQUOTE> <div dir=ltr> </div> <div dir=ltr>def GetName(self):</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div
dir=ltr>return self.name</div></BLOCKQUOTE></BLOCKQUOTE> <div dir=ltr> </div> <div dir=ltr>So now I unpickle my object from before using my new program. and I use MyVar.GetName(). does this work? If not, how do people usually handle this type of problem? or do they not use the pickler to save program data?</div> <div dir=ltr> </div> <div dir=ltr>big thanks!</div> <div dir=ltr> </div> <div dir=ltr>Jeff</div><p> 
<hr size=1>Fussy? Opinionated? Impossible to please? Perfect. <a href="http://us.rd.yahoo.com/evt=48516/*http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 ">Join Yahoo!'s user panel</a> and lay it on us.