Meaningless Drivel is fun!*
The moose likes Jython/Python and the fly likes Calling python function from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Calling python function from java" Watch "Calling python function from java" New topic
Author

Calling python function from java

Raj Sikka
Ranch Hand

Joined: Apr 11, 2003
Posts: 34
Hi ,
I have a java file as below :
public class myClass
{
public int myMethod() {
PythonInterpreter interpreter = new PythonInterpreter();
//Code to write
}
}
I have one python file as below :
import string;
from jythonlib.tl1pc.utils import *
class myPythonClass:

def abc(self):
print "calling abc"
tmpb = {}
tmpb = {
'status' : 'SUCCESS'
}
return tmpb
Now the problem is i want to call "abc" function of my python file from "myMethod" method of my java file.
How to make these kind of calls ? Pls explain me with piece of code.
Thanks in advance,
Raj

Raj - please do not use URGENT in your topic title (So called URGENT topics are likely to be ignored or made fun of)
[ January 14, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Before you started playing around with embedding the Jython interpreter, did you consider this method from the Jython FAQ?

If you really need embedding, then there's a trivial example here.
The book Jython for Java Programmers has a whole chapter dedicated to embedding the Jython/Python interpeter into Java programs. Maybe you can download the examples from the book.
Jython Essentials also covers using the Jython interpreter from Java.
[ January 14, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Raj Sikka
Ranch Hand

Joined: Apr 11, 2003
Posts: 34
Thanks for your reply Barry.
Where can I download examples from the book "Jython for Java Programmers"?
Are they available free on net ?
If yes can you please tell me the link.
Thanks,
Raj
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I guess it's the book's companion website. But's not reachable at the moment
Raj Sikka
Ranch Hand

Joined: Apr 11, 2003
Posts: 34
Thanks Berry,
I will try to download.
Raj
eswari Malluru
Greenhorn

Joined: Jul 07, 2008
Posts: 7
Hi Raj Sikka,

I am also trying for similar example. Please give an example if you downloaded and implemented this. I failed in downloading this book.

Thanks,
Eshwari
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling python function from java
 
Similar Threads
urgent
Urgent....
Urgent !
file not found when calling execfile function
URGENT!!!!!!!!