[gnosis/xml_pickle] How to unpickle nested objects?

F. GEIGER fgeiger at datec.at
Tue Dec 17 03:44:04 EST 2002


I do pickle/unpickle to persist my data between program runs. There's a top
object, which contains additional objects, which contain additional objects
etc. Everything is pickled and on unpickling this one object I receive the
whole hierarchy. Cool.

Now I'd like to change from normal pickle format to XML format. As I want to
do this in a "painless" way, I tried xml_pickle from the gnosis pack 1.0.5.

Here one has to write

xml_pickle.Contact = Contact
c = xml_pickle.XML_Pickler().load(file)

to receive a Contact object with methods too (otherwise the unpickled object
would only contain the attributes).

This works fine until Contact contains an object of class say Address. If
Contact is unpickled now, there's no code executed similar to the above one:

xml_pickle.Address = Address

which makes the Contact's Address object contain only data, no methods.

Is there an easy way to overcome this?

Many thanks in advance and kind regards
Franz GEIGER







More information about the Python-list mailing list