By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

'Deep' pickling

P: n/a
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[i] 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

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.