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
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: 8
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:
subject: How to call a Python method form Java class
It's not a secret anymore!