473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

'Deep' pickling

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
0 1034

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: gong | last post by:
hi i would like to pickle a lambda; according to the library docs in 2.3, i believe this shouldnt be possible, since a lambda is not a function defined at the top level of a module (?) ...
1
by: Marc | last post by:
Hi all, After some research I've decided that my previous question (Confusing problem between Tkinter.Intvar...) was headed in the wrong direction. Partly because I think I have a greater...
1
by: Edward Loper | last post by:
I'm having trouble pickling subclasses of dict when they contain cycles. In particular: >>> import pickle >>> class D(dict): pass >>> d = D() >>> d = d # add a cycle. >>> print d {1: {...}}...
8
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a long running application (electromagnetic compatibility measurements in mode-stirred chambers over GPIB) that use pickle (cPickle) to autosave a class instance with all the...
2
by: Kirk Strauser | last post by:
I have a module that defines a Search class and a SearchResult class. I use these classes by writing other modules that subclass both of them as needed to interface with particular search engines....
0
by: jkn | last post by:
Hi all this is my first go at pickling and I'm having trouble with variables of type VT_DATE returned from a COM application. I don't seem to be successfully pickling/depickling to the the same...
0
by: Shahin Saadati | last post by:
Hi, The following sample code is to pickle and unpickle an object. It works fine with CPython, but the unpickling fails in Jython and I receive an error stating that "A" is unsafe to unpickle...
9
by: Alex | last post by:
I have a serious problem and I hope there is some solution. It is easier to illustrate with a simple code: >>> class Parent(object): __slots__= def __init__(self, a, b): self.A=a; self.B=b...
0
by: Irmen de Jong | last post by:
I'm having troubles pickling classes that extend Exception. Given the following source: class Foo(object): def __init__(self, m): self.m=m class Bar(Exception): def __init__(self, m):
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.