import org.python.core.*; public class PyObjectExample { public static void main(String[] args) { PythonInterpreter interpreter = new PythonInterpreter(); // create a Python string object PyObject object = new PyString("Hello World!"); // print the length of the string System.out.println(object.__len__()); } }
import org.python.core.*; public class PyObjectExample { public static void main(String[] args) { PythonInterpreter interpreter = new PythonInterpreter(); // define a Python function interpreter.exec("def my_function(a, b):\n\treturn a + b"); // create arguments for the function PyObject a = new PyInteger(1); PyObject b = new PyInteger(2); // call the function and pass the arguments PyObject result = interpreter.eval("my_function(" + a + ", " + b + ")"); // print the result System.out.println(result.asInt()); } }In both examples, the package library used is "org.python.core".