• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to call a Python method form Java class

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


#processing.py

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

try:
................
...........


and my java class is as below:

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

System.out.println();
interp.execfile("E:\\processing.py");


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


Thanks,
Eshwari
 
Ranch Hand
Posts: 152
VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here you go...

Java:


Python


HTH
Matt
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone tell me how do I call a particular method in Python with parameters from java?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic