我用了java调用python的方法执行没问题代码如下:
import javax.script.*;
import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import java.io.;
import static java.lang.System.;
public class Start {
public static void main(String[] args)
{
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days[4];");
System.out.println(CallPython());
}
private static String CallPython()
{
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("D:\\Java\\Python4Android\\test.py");
PyFunction func = (PyFunction)interpreter.get("add",PyFunction.class);
int a = 2020, b = 2 ;
PyObject pyobj = func.__call__(new PyInteger(a), new PyInteger(b));
return pyobj.toString();
}
}
但是我把代码内嵌至安卓里面就行了,我也导包了:
跪求大佬