473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

possible to pass python objects into java without jython?

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

Jul 18 '05 #1
5 3665
Maurice Ling <ma*********@acm.org> 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 <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #2
Maurice Ling wrote:
Are there any way out in this?


No.

Jul 18 '05 #3
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
Jul 18 '05 #4

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
Jul 18 '05 #5
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
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bezeee | last post by:
At my work we are in the process of building a tool to test an XML based API. Basically, XML in and XML out over http. Currently, there are two engines that do all of the schema validations, xml...
6
by: Dave Benjamin | last post by:
Hey good people, I've been doing a lot of simultaneous Jython and CPython programming lately, and just wanted to say, with no intended ill will toward any of the individuals who have been...
0
by: vincent Salaun | last post by:
hi all, here's my problem : I've embedded a python interpreter in our java application (based on the NetBeans palteforrm) using the Jython API : http://www.jython.org/docs/javadoc/index.html...
13
by: Ajay | last post by:
hi! can you call a Python application from a Java program? does this require any additional package to be installed? thanks cheers
10
by: Maurice Ling | last post by:
Hi, I'm a postgraduate and my project deals with a fair bit of text analysis. I'm looking for some libraries and tools that is geared towards text analysis (and text engineering). So far, the...
4
by: Ramza Brown | last post by:
I know you may frown at my use at java, but this is a pretty simple way to create GUIs quickly, using Java's swing. I have some code for an approach for integrating the swing GUI components and...
2
by: Hal Vaughan | last post by:
I'm self taught and most of what I've been working on for the past several years has been entirely in Perl and Java. I've noticed that I can code about 5 times faster in Perl than Java, in part...
34
by: Anthony Irwin | last post by:
Hi All, I am currently trying to decide between using python or java and have a few quick questions about python that you may be able to help with. #1 Does python have something like javas...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.