473,748 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3684
Maurice Ling <ma*********@ac m.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.or g> 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
3031
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 diffs, sending/receiving, etc. One of these engines in implemented in C# and the other in Java. Now the choice comes down to which scripting language we choose (Perl, Python or Jython) to tie into one of these engines. The scripting language...
6
2109
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 generous enough to make the two languages possible, that, well, they're kinda different. I guess it was inevitable, but with Jython stuck at Python 2.1, it's not really the same language as CPython is today. You still have to type "from __future__...
0
1998
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 So, i've used the PythonInterpreter class to instanciate an interpreter and to integrate it but the its environnement doesn't seem to be the
13
3344
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
2900
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 most comprehensive toolkit in python for my purpose is NLTK (natural language tool kit) by Edward Loper and Steven Bird, followed by mxTextTools. Are there any OSS tools out there that is more comprehensive than NLTK? In the Java world, there is...
4
1540
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 python. I threw the project together in a couple of days, so it is not some massive application. And, I have some little models(hehe). Anyway, if you want to check out an approach for working with Jython, here it is. Some questions, I do get...
2
1811
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 because I feel like whenever I want to do something in Java, I have to create an object, do a few preperatory things, then do what I need, but in Perl, I just call the routine. Java, however, does much better at cross platform apps, especially if...
34
3691
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 .jar packages. A jar file contains all the program files and you can execute the program with java -jar program.jar I am sort of hoping python has something like this because I feel it
0
8991
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, 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...
0
8830
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,...
0
9541
Oralloy
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...
0
9370
jinu1996
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...
0
6074
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();...
0
4602
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...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.