- Create a python interpreter inside
Java using Jython.
- Execute your python code using the interpreter.
- Get a handle to your python function
- Invoke it
class Classifier:
def classify(i: int):
return i + 1
def main():
classifier = Classifier()
import org.python.core.PyException;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws PyException {
PythonInterpreter interp = new PythonInterpreter();
interp.execfile();
PyObject classifer = interp.get("classifier");
PyObject x = foo.invoke("classify", new PyInteger);
System.out.println("x: " + x);
}
}