> >
> OK, but do be aware that slots was intended solely as a
> memory-conservation measure where large numbers of objects are being
> created. You are therefore subverting its true intent by using it to
> limit the assignment of extra attributes (and there has been much recent
> discussion on thi
Alex wrote:
> Thanks to both Alex Martelli and Steve Holden.. We need __slots__ for
> other reasons, too long to explain, but basically to prevent assignment
> of extra attributes.
>
> I ended up changing child classes this way:
>
> def __getstate__(self):
> return(Parent.__getstate__
Thanks to both Alex Martelli and Steve Holden.. We need __slots__ for
other reasons, too long to explain, but basically to prevent assignment
of extra attributes.
I ended up changing child classes this way:
def __getstate__(self):
return(Parent.__getstate__(self), self.C)
def __se
Alex wrote:
> 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__=['A', 'B']
> def __init__(self, a, b):
> self.A=a; self.B=b
> def __getstate__(self):
>
Alex <[EMAIL PROTECTED]> wrote:
> 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__=['A', 'B']
> def __init__(self, a, b):
> self.A=a; self.B=b
> def __getstate__(s
Thanks so much! It makes perfect sense and I am sure it will work now.
--
http://mail.python.org/mailman/listinfo/python-list
Of course, in __setstate__, there should be a tup = list(tup) as well -
sheer forgetfulness and a confusing name in one.
--
http://mail.python.org/mailman/listinfo/python-list
The reason the state of obj.A and obj.B aren't preserved is because
your __getstate__ and __setstate__ don't preserve them - they only save
obj.C, and you don't make a call to the parent class's respective
methods. Here's what I mean:
>>> import pickle
>>> class Child(Parent):
__slots__=[
Sorry, I copied and pasted a wrong piece from shell at one part of the
code:
objct.Z=4 was in fact obj.Z=4 and it did refuse to accept Z (because it
is not in __slots__).
But the question remains: why the value of attribute A is not preserved
during pickling and unpickling and what can be done ab
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__=['A', 'B']
def __init__(self, a, b):
self.A=a; self.B=b
def __getstate__(self):
return self.A, self
10 matches
Mail list logo