今天,给大家介绍下如何在java用jython的方法得到Python数据并把它转换为java下数据类型.下面我们进入正题:
我们使用的jython的jar包版本为2.70,然后在引入jar包jythonutils1.0
例如下面是之前只用jython2.70常用方法:
import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
/**
* 在java中调用本机python脚本中的函数
*
* @author liuyazhuang
*
*/
public class FirstJythonScript {
public static void main(String args[]) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("D:/Workspaces/J2EE/Test/config/my_utils.py");
PyFunction func = (PyFunction) interpreter.get("adder", PyFunction.class);
int a = 2010, b = 6;
PyObject pyobj = func.__call__(new PyInteger(a), new Py