原文地址:https://www.cnblogs.com/ybf-yyj/p/8344139.html
java代码:
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("/home/ybf/PycharmProjects/first/1.py");
PyFunction func_third= (PyFunction)interpreter.get("third",PyFunction.class);
PyObject pyobj = func_third.__call__(new PyInteger(4), new PyInteger(2));
System.out.println(pyobj);
python代码:
def third(a,b):
c=sub(a,b)
d=sub(b,a)
return c*d
def sub(a,b):
return a-b