[Tutor] pickle question

Jeff Peery jeffpeery at yahoo.com
Wed Sep 26 01:37:15 CEST 2007


hello, 
   
  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?
   
  here's an example if I didn't explain myself well...
   
  I create a class of data called 'var'
   
  class var:
    def __init__(self):
    self.data = numpy.array([1,2,3,4])
  self.color = 'blue'
   
  def operate(self):
    return self.data+1
   
  now create the instance: 
  myVariable = var()
  I then pickle it to some file. and now I continue to develop my class module:
   
  class var:
    def __init__(self):
    self.data = numpy.array([1,2,3,4])
  self.color = 'blue'
  self.name = 'bob'
   
  def operate(self):
    return self.data+1
   
  def GetName(self):
    return self.name
   
  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?
   
  big thanks!
   
  Jeff

       
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070925/6e3f4f71/attachment.htm 


More information about the Tutor mailing list