pass data from java to python and back jython -
i using jython run python script java. able send data python script command line arguments when invoke script using pythoninterpreter
.
now want call java method within jython script, passing list
method argument. how do that?
i posting code both passing of data java -> python , python -> java. hope helps !! in this, string array "s" passed python script , python, "city" list passed python java through function call getdata().
javaprog.java:
import org.python.core.pyinstance; import org.python.util.pythoninterpreter; public class javaprog { static pythoninterpreter interpreter; @suppresswarnings("resource") public static void main( string gargs[] ) { string[] s = {"new york", "chicago"}; pythoninterpreter.initialize(system.getproperties(),system.getproperties(), s); interpreter = new pythoninterpreter(); interpreter.execfile("pyscript.py"); pyinstance hello = (pyinstance) interpreter.eval("pyscript" + "(" + "none" + ")"); } public void getdata(object[] data) { (int = 0; < data.length; i++) { system.out.print(data[i].tostring()); } } }
pyscript.py:
import javaprog class pyscript: def __init__(self,txt): city = [] in range(0,len(sys.argv)): city.append(str(sys.argv[i])) jobj = javaprog() jobj.getdata(city) print "done!"
Comments
Post a Comment