possible to pass python objects into java without jython?

Maurice LING mauriceling at acm.org
Wed Nov 10 04:55:27 CET 2004

> The simple answer is no. The complex answer is maybe, but not without 
> some work on your part.
> As part of JPype I made the opposite : allow Python to use Java classes. 
> That was easy as python is very dynamic.
> Going the other way around .... I don;t see how. The java part must want 
> to receive a specific Java type. Even if that type is Object (the root 
> of all object types in Java), tehre is no way for Python object to be 
> one of those.
> Case #1 : the "main" program is in Python, and the Java type to be 
> received is a Java interface. In that specific case, JPype 
> (http://jpype.sourceforge.net) can help you. You can "wrap" your pO into 
> the correct Java type and apss it in.
> Otherwise, as has been mantioned before, you will need some kind of 
> remoting mechanism. Corba might provide a middle ground, or XML-RPC/SOAP.
> Good luck.
> Steve


Referring to this scenario again.....

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)

Perhaps if we lax the problem a little and allow Jython to be in 
consideration and pB.py is implemented in Jython (as jyB.py), then using 
jythonc to convert it into a Java package (jyB.jar containing 
jython.jar, jyB.class and jyB$Inner.class). Am I then able to import jyB 
in my Java codes? Is it possible to use Jython as the middle ground, 
instead of CORBA or SOAP etc etc?


More information about the Python-list mailing list