'Deep' pickling

  • Thread starter jeanphilippe.aumasson
  • Start date
J

jeanphilippe.aumasson

Hi,

I have some problems when pickling an instance of a class, i don't
retrieve all its attributes instances after loading. I'm quite a
beginner in Python, so it may be a stupid error... Here the full
description :

I have a class Test, having an attribute self.problem, as an instance
of Problem class, defined in the same module.
Problem as an attribute self.optimum, that is a list of Point
instances, also defined in the same module.
So i use to write self.problem.optimum to get some Points of my
Test...

I pickle a Test with the following lines :
import copy
cPickle.dump( copy.deepcopy(self), open('TEST', 'w'))
and unpickle in another module with :
fd = open( os.path.join(p, 'TEST'), 'r' )
s = cPickle.load( fd )

But the problem is, when i try to access the self.problem.optimum
field, i get an empty list, instead of having a list full of Points. I
can access string, int, or even Point attributes of Problem. This only
happens when i load AFTER restarting Python interpreter.

I thought that pickling self from my Test wasn't enought to get
instances of attributes copied to, that's why i used a deepcopy(self)
instead, but it didn't resolve my problem... I tryed to define a
__getState__() method, but didn't help...

Can someone help ?

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top