Update with pickle

Stefan Seefeld seefeld at sympatico.ca
Thu May 27 09:31:00 EDT 2004


Matteo Dell'Amico wrote:
> Nicolas Fleury wrote:
> 
>> I think it is acceptable that this pickle.update function would only 
>> accept reference of same type and raise an exception otherwise.  The 
>> point of pickle.update would be to not "replace an object with another 
>> one" but to call __init__ on an existing object.
> 
> 
> I still don't understand how exactly you would want it to work. If you 
> want to call __init__ on an existing object, why don't you just do it 
> explicitly? Could you post some equivalent code to what you would want 
> pickle.update to do?

Think of a 'persistence storage service' that could look like this:

store = Persistence.Store('foobar')

object.store(store) # persists the object's state into the store

...

object.restore(store) # restore the object's state from the store

Of course, here 'object' has to implement some 'Storable' interface,
so it's quite intrusive (and thus not really what Nicolas is looking for).
It's just to illustrate the purpose, anyways.
With python's metaprogramming and introspection capabilities the same
could be achieved without the need for a specific base class. Well,
may be a specific __metaclass__, I don't know.

It really seems to me that pickle already contains the functionality
that would be required (after all pickle *can* deal with object graphs,
so it has to track object ids internally), it just needs to be exposed
to the user. I believe that's precisely what Nicolas' enhancement request
is all about.

Regards,
		Stefan




More information about the Python-list mailing list