public class FirstJavaScript
{
public static void main(String args[])
{
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("C:\\Python27\\programs\\my_utils.py");//路徑,指令碼名稱
PyFunction func = (PyFunction)interpreter.get("adder",PyFunction.class);//adder python函數名
int a = 2010, b = 2 ;
PyObject pyobj = func.__call__(new PyInteger(a), new PyInteger(b));//傳值,a b
System.out.println("anwser = " + pyobj.toString());
}//main
}
得到的結果是:anwser = 2012
3.使用java直接執行python指令碼,
建立指令碼inputpy
view plain
#open files
print 'hello'
number=[3,5,2,0,6]
print number
number.sort()
print number
number.append(0)
print number
print number.count(0)
print number.index(5)
public class FirstJavaScript
{
public static void main(String args[])
{
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("C:\\Python27\\programs\\input.py");
}//main
}