Persistence

Chris Liechti cliechti at gmx.net
Thu Apr 11 16:29:38 EDT 2002


Rajarshi Guha <rxg218 at psu.edu> wrote in
news:a94qk5$22mg at r02n01.cac.psu.edu: 

> On Thursday 11 April 2002 13:58 in comp.lang.python Riccardo de Maria
> wrote: 
> 
>> Is there a way to save in a file the status, objects, functions of
>> interpreter
>> in order to restore it after the interpreter has been closed?
>> 
>> If it is possible, one can work on a project stop and then continue
>> later adding functions, objects and so on.

thats a question for an IDE with such functionality. i don't know one but i 
think it should be easy to store all objects in the global namespace of the 
interpreter and load it again on next startup.
the textual history of the interpreter with all the outputs must be saved 
separately.

> I have a related question - does the OP refer to object persistence or
> object serialization? Is there a difference between the two?

just serializing an object does not mean that its persistent. you can send 
a serialized object through the net or you can use to store it on disk.
 
> I looked at the shelve and pickle modules - the former uses a dbm
> database whereas the latter just dumps an ASCII representation of the
> object. The fact that shelve uses a dbm indicates that it should be
> more efficient. Is this true? When would I choose one over the other?

i think pickle is more versatile. the serialized object can be stored in a 
file, sent over the net (see e.g. PYRO.sf.net), put in a database etc.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list