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
ObjectOutputStr eam (from jython).
I prefer to do it file based ...something like
pickle.dump(som eObj, open("output.tx t", "w"))
as opposed to shelve
f = shelve.open("ou tput.txt")
f['somedata'] = someObj
Thanks for the help in advance. 6 2159
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 ObjectOutputStr eam (from jython).
I prefer to do it file based ...something like
pickle.dump(som eObj, open("output.tx t", "w"))
as opposed to shelve
f = shelve.open("ou tput.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
Noah wrote: You can give up on pickle, because pickle is only guaranteed to work with the exact same version of the Python interpreter.
:(
How complex of a serialization do you need?
simple
I just wrote the info out to a file. then i have a thread which reads
in the files and parses them and creates the necessary object.
thanks anyway
"py" <co*******@gmai l.com> writes: Noah wrote: You can give up on pickle, because pickle is only guaranteed to work with the exact same version of the Python interpreter.
:(
No that's confusing pickle with marshal. Pickle is supposed to work
across versions, though it has recently grown a few slightly
incompatible optional modes.
"Noah" <no**@noah.or g> wrote: 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.
nope.
maybe you're thinking of marshalled bytecode, but I don't think
that's what the OP was talking about.
</F>
Noah wrote: You can give up on pickle, because pickle is only guaranteed to work with the exact same version of the Python interpreter.
Not true. You're thinking of marshal.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Who knows whether any of us will be around in 1972?
-- John F. Kennedy
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 ObjectOutputStr eam (from jython).
I prefer to do it file based ...something like
pickle.dump(som eObj, open("output.tx t", "w"))
as opposed to shelve
f = shelve.open("ou tput.txt") f['somedata'] = someObj
It works for me. I think the problem is that your pickle file is not closed properly, when
I tried it with the form you have above the file was never written. Here is an example
that works with Jython 2.1 and Python 2.4.2:
D:\WUTemp>jytho n
Jython 2.1 on java1.4.2_06 (JIT: null)
Type "copyright" , "credits" or "license" for more information. a='hello world' b=tuple(range(1 0)) c={ 'a':1, 'b':2, 'c':3} class Foo:
.... pass
.... d=Foo() lst=[a,b,c,d] lst
['hello world', (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), {'b': 2, 'a': 1, 'c': 3}, <__main__.Foo
instance at 17930334>] f=open('pickle. txt', 'wb') import pickle pickle.dump(lst , f) f.close() ^Z
D:\WUTemp>pytho n
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright" , "credits" or "license" for more information. import pickle class Foo:
... pass
... f=open('pickle. txt') lst = pickle.load(f) f.close() lst
['hello world', (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), {'a': 1, 'c': 3, 'b': 2}, <__main__.Foo
instance at 0x00A51350>]
Kent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Chermside |
last post by:
Ype writes:
> For the namespaces in Jython this 'Python internal thread safety'
> is handled by the Java class:
>
> http://www.jython.org/docs/javadoc/org/python/core/PyStringMap.html
>
> which has almost all of it public methods Java synchronized:
>
>
http://cvs.sourceforge.net/viewcvs.py/jython/jython/org/python/core/PyStringMap.
|
by: angel |
last post by:
A java runtime environment includes jvm and java class (for example
classes.zip in sun jre). Of course jython need jvm,but does it need java
class.
Thanx
|
by: Jim Hargrave |
last post by:
I've read that it is possible to compile jython to native code using
GCJ. PyLucene uses this approach, they then use SWIG to create a Python
wrapper around the natively compiled (java) Lucene. Has this been done
before for with jython?
Another approach would be to use JPype to call the jython jar directly.
My goal is to be able to script Java code using Jython - but with the
twist of using Cpython as a glue layer. This would allow...
|
by: Gregor Stich |
last post by:
Dear all,
I hope my question is here in the right place...
What I want to achieve is a communication between Java and Python. We
have a pretty strong framework of existing python scripts and modules.
Now I want to use jython in order to faciliate the communication
between another Java framework.
But I`m currently stuck with jython: Trying to import the user-defined
python modules, these cannot be found. I read a lot about the jython
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |