possible to pass python objects into java without jython?

Josiah Carlson jcarlson at uci.edu
Wed Nov 10 03:06:45 EST 2004


Maurice Ling <mauriceling at acm.org> wrote:
> Jeremy Jones wrote:
> 
> > Maurice Ling wrote:
> >
> >> Hi,
> >>
> >> I have read that this had been asked before but there's no 
> >> satisfactory replies then.
> >>
> >> I have a module (pA) written in python, which originally is called by 
> >> another python module (pB), and passes a python object (pO) to pB. 
> >> Now I require pA to be called in a java class (jC) and pass pO into 
> >> jC. As pA uses non-python modules, I am not able to use Jython on this.
> >>
> >> Are there any way out in this?
> >>
> >> Thanks in advance.
> >>
> >> Maurice
> >
> > How about:
> >
> >     * XMLRPC
> >     * SOAP
> >     * a messaging queue of some sort (pA or pB - I'm a little unclear
> >       on which is the starting point - could put pO in a message queue
> >       and jC could pick it up)
> >     * serialize the Python object to disk in an intermediate format
> >       (say, XML) and have the Java process pick it up
> >     * CORBA
> >
> > Without more details, and some clarification, that's the best I can 
> > do.  Are you sure you meant to say pA is called by pB, or is it the 
> > other way around?  If pA is being called, it really can't pass pO to 
> > pB, unless you've got a callback setup.
> >
> >
> > Jeremy Jones
> 
> Say this scenario...
> 
> pA.py contains
> imports (something non-pure python)
> def A(n):
>     ...(does something)...
>     returns pO
> 
> pB.py comtains
> import pA
> def B(n):
>     (does something)
>     x = pA.A(n)
>     (does more things)
> 
> How can I get Java to call pA.A function and then receives the object it 
> returns? I am considering SOAP or CORBA, but just wondering if there is 
> any other ways without resorting to network or socket programming, since 
> all modules are on the same machine?


Python and Java are two different languages with two differen runtimes 
(except in the case of Jython, which you said you didn't want to use). 
You can't just call a function or method from the other (except in the
case of Jython, which you said you didn't want to use).  You /can/ use
IPC (files, sockets, pipes, corba, etc.) to result in a method call and
data transfer, but you can't just use 'data = python_runtime.module_pB.B(n);'
from Java (except in the case of Jython,
which you said you didn't want to use).

 - Josiah




More information about the Python-list mailing list