serialize object in jython, read into python

Noah noah at noah.org
Thu Dec 22 16:02:56 EST 2005


py wrote:
> I want to serialize an object in jython and then be able to read it in
> using python, and vice versa.
>
> Any suggestions on how to do this?  pickle doesnt work, nor does using
> ObjectOutputStream (from jython).
>
> I prefer to do it file based ...something like
>
> pickle.dump(someObj, open("output.txt", "w"))
>
> as opposed to shelve
>
> f = shelve.open("output.txt")
> f['somedata'] = someObj
>
> Thanks for the help in advance.

You can give up on pickle, because pickle is only
guaranteed to work with the exact same version of the Python
interpreter.
(It will work on the same version of the Python interpreter on
different platforms, but
that's probably not useful to you here).

How complex of a serialization do you need?
Would simply saving a dictionary of strings work for you?
That's what I do for HTTP session management.
I then map my session dictionary to the dictionary of object
attributes.

You might also consider JSON which is very simple and lightweight.
    http://www.json.org/

Yours,
Noah




More information about the Python-list mailing list