A
Alex
I have a serious problem and I hope there is some solution. It is
easier to illustrate with a simple code:
__slots__=['A', 'B']
def __init__(self, a, b):
self.A=a; self.B=b
def __getstate__(self):
return self.A, self.B
def __setstate__(self, tup):
self.A, self.B=tup
__slots__=['C',]
def __init__(self, c):
self.C=c
def __getstate__(self):
return self.C,
def __setstate__(self, tup):
self.C, =tup
Traceback (most recent call last):
File "<pyshell#60>", line 1, in -toplevel-
objct.Z=4
AttributeError: 'Child' object has no attribute 'Z'
So far so good.. Object obj inherited attributes (A and B) from the
parent class and refuses to take any new ones. But look what happens
when I try to pickle and unpickle it:
Traceback (most recent call last):
File "<pyshell#55>", line 1, in -toplevel-
objct.A
AttributeError: A1
Its own attribute (C) value is restored but the value of an inherited
attribute (A) is not. I tried pickling protocol 2, and module pickle
instead of cPickle, all with the same result.
What can be done?! Or maybe nothing can be done?
I would greatly appreciate an advice. A lot of code is written, but now
we have a need for pickling and unpickling objects and discovered this
problem.
easier to illustrate with a simple code:
__slots__=['A', 'B']
def __init__(self, a, b):
self.A=a; self.B=b
def __getstate__(self):
return self.A, self.B
def __setstate__(self, tup):
self.A, self.B=tup
__slots__=['C',]
def __init__(self, c):
self.C=c
def __getstate__(self):
return self.C,
def __setstate__(self, tup):
self.C, =tup
Traceback (most recent call last):
File "<pyshell#60>", line 1, in -toplevel-
objct.Z=4
AttributeError: 'Child' object has no attribute 'Z'
So far so good.. Object obj inherited attributes (A and B) from the
parent class and refuses to take any new ones. But look what happens
when I try to pickle and unpickle it:
Traceback (most recent call last):
File "<pyshell#55>", line 1, in -toplevel-
objct.A
AttributeError: A1
Its own attribute (C) value is restored but the value of an inherited
attribute (A) is not. I tried pickling protocol 2, and module pickle
instead of cPickle, all with the same result.
What can be done?! Or maybe nothing can be done?
I would greatly appreciate an advice. A lot of code is written, but now
we have a need for pickling and unpickling objects and discovered this
problem.