wood burning stoves 2.0*
The moose likes Jython/Python and the fly likes How to call a Python method form Java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "How to call a Python method form Java class" Watch "How to call a Python method form Java class" New topic

How to call a Python method form Java class

eswari Malluru

Joined: Jul 07, 2008
Posts: 7
Hi All,

I new to python and want to call python script from java class. For this using python interpreter and able to do so. But want to call a particular python method from java class.

Python script using is as show below:


import os
import datetime

class Processing(object):
Processing class.
def __init__(self, gui):
self.gui = gui
self.numbers = None
self.vendor = None
self.raNumber = None
self.comPort = None
self.logFile = None
self.thread = None
self.results = None
self.testSuite = None
self.retryEvent = None

def run(self,logFile,comPort,numbers,vendor,raNumber,testSuite,SerialErrorEvent,ProcessingErrorEvent):
self.logFile = logFile
self.comPort = comPort
self.serialNumbers = serialNumbers
self.vendor = vendor
self.raNumber = raNumber
self.SerialErrorEvent = SerialErrorEvent
self.ProcessingErrorEvent = ProcessingErrorEvent


and my java class is as below:

PythonInterpreter.initialize(System.getProperties(), System.getProperties(), new String[0]);
PythonInterpreter interp = new PythonInterpreter();


Now want to call the method run from java class. Please tell me how to do this with a sample code

Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149

here you go...



I agree. Here's the link: http://aspose.com/file-tools
subject: How to call a Python method form Java class
Similar Threads
AttributeError when calling pyhton scripts from java class
Help - How to I tell java where my jython.py script is located in the Directory
file not found when calling execfile function
Calling python function from java
Executing Jython script from java and accessing resulting object