Update with pickle
Stefan Seefeld
seefeld at sympatico.ca
Wed May 26 01:51:16 EDT 2004
Hi there (,hi Nicolas !),
I'v been looking for something similar recently,
so this thread caught my attention, but...
Leif K-Brooks wrote:
> Using __slots__ is just an optimization, it isn't directly related to
> the example. This would also work:
>
>
> class cls:
> def __init__(self, foo=None):
> self.foo = foo
>
> def set_foo(self, foo):
> self.foo = foo
>
>
> foo = cls(42)
> bar = foo
> print bar.foo # 42
> foo.set_foo(43)
> print bar.foo # 43
...I'm still lost: how is this interface-enriched declaration helping
in the task to retrieve ('internalize') an object's state from a pickle ?
Even if I set the object's state via some 'set' manipulators, I still have
to retrieve the state from the pickle and identify the object it is targetted at.
Looking again into the docs for the pickle protocol, I wonder whether there
isn't any place in the __init__/__reduce__/__setstate__ magic to throw in
some meta-programming (i.e. an intelligent metaclass doing the job), or providing
a clever __new__ operator that doesn't return a new object but an existing one,
etc., etc.
Regards,
Stefan
More information about the Python-list
mailing list