possible to pass python objects into java without jython?

Discussion in 'Python' started by Maurice Ling, Nov 9, 2004.

  1. Maurice Ling

    Maurice Ling Guest

    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
     
    Maurice Ling, Nov 9, 2004
    #1
    1. Advertising

  2. Maurice Ling

    Mike Meyer Guest

    Maurice Ling <> writes:

    > 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?


    CORBA.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Nov 9, 2004
    #2
    1. Advertising

  3. Maurice Ling wrote:

    > Are there any way out in this?


    No.
     
    Istvan Albert, Nov 9, 2004
    #3
  4. Maurice Ling

    Steve Menard Guest

    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


    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
     
    Steve Menard, Nov 10, 2004
    #4
  5. Maurice Ling

    Maurice LING Guest


    >
    > 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


    Hi,

    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?

    Thanks
    Maurice
     
    Maurice LING, Nov 10, 2004
    #5
  6. Maurice Ling

    Steve Menard Guest

    Maurice LING wrote:
    >
    >>
    >> 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

    >
    >
    > Hi,
    >
    > 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?
    >
    > Thanks
    > Maurice


    Jython has a Java API that allows calling Python code. The simplest way
    however would be to turn your pB into a class implementing a given Java
    interface. Then java code can easily instantiate your Python class and
    use it through the interface.

    However the problem remains ... just what kind of object is this pO ?
    Using Jython will not magically allow regular Java code to understand
    python objects. NAd you still have to bridge between CPython and Jython ...

    Steve
     
    Steve Menard, Nov 10, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David McNab
    Replies:
    0
    Views:
    522
    David McNab
    Apr 9, 2004
  2. Maurice Ling
    Replies:
    1
    Views:
    323
    Diez B. Roggisch
    Nov 9, 2004
  3. py
    Replies:
    6
    Views:
    704
    Kent Johnson
    Dec 23, 2005
  4. Divya Prakash
    Replies:
    0
    Views:
    469
    Divya Prakash
    Dec 19, 2006
  5. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    374
    Pinegar, Kent T
    Jul 24, 2008
Loading...

Share This Page