Stefan,

 

Thanks very much for the example and suggestions.  Unfortunately, I have no control over how the data are serialized.

 

Would you mind also providing an example of depickling from within Java (i.e. using the jython jar)?  This is really the usage I’m trying to get running, and I’ve had a very tough time.

 

Thanks again,

 

 

Ulises Melendez


From: Stefan Eischet [mailto:stefan@eischet.com]
Sent: Thursday, August 07, 2008 3:05 AM
To: Melendez,Ulises
Cc: jython-users@lists.sourceforge.net
Subject: Re: [Jython-users] Unpickling from Java

 

Hello Ulises,

 

to confirm that the basics work, I've just tried unpickling a simple tuple successfully:

 

$ python

Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) 

[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import pickle

>>> data = (1,2,3,4,5,)

>>> pickle.dumps(data)

'(I1\nI2\nI3\nI4\nI5\ntp0\n.'

>>> ^D

 

$ jython

Jython 2.5a1+ (asm:4943:4945, Jul 15 2008, 15:30:04) 

[Java HotSpot(TM) Client VM (Apple Inc.)] on java1.5.0_13

Type "help", "copyright", "credits" or "license" for more information.

>>> import pickle

>>> pickle.loads('(I1\nI2\nI3\nI4\nI5\ntp0\n.')

(1, 2, 3, 4, 5)

>>> ^D

 

YMMV with other Jython versions, of course. Two things you might want to look at are the protocol parameter of the pickle module (which defaults to 0, and which should be fine... see http://docs.python.org/lib/node315.html). There's also a discussion about certain problems and workarounds for floating point values: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2005-09/msg01079.html

 

What I usually do instead of pickling is to serialize/deserialize simpler data structures (mainly dicts) into JSON: http://www.JSON.org/ and read them from Java code. So, instead of pickling an object I just dump its interesting properties into a dict and read them back from the dict representation when needed. This also works fine when using plain Java instead of Java+Jython. Maybe you'll have more success with that approach.

 

Regards

Stefan

 

On 2008-08-07, at 02:10 , Melendez,Ulises wrote:



I have a python object that’s been pickled to a file, and I need to unpickle it from within a Java VM.  I’ve searched around and fooled around with cPickle (.java), but I’m having no such luck.  Can anyone point me to an example of unpickling a pickled object within Java?  I can also provide some of my failed attempts for public ridicule, if that would help.

 

Thanks in advance,

 

 

Ulises Melendez

 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users