您的位置:首页 > 编程语言 > Python开发

java掉用python

2015-11-05 22:08 537 查看

这是java调用Python脚本的代码

如果python中需要传入俩个参数时怎可以像下面获得参数

PyObject pyobj = func.__call__(new PyString(cc), new PyString(dd));



import javax.naming.spi.ObjectFactory;
import javax.script.*;

import org.python.apache.xerces.util.URI;
import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.core.PyType;
import org.python.util.PythonInterpreter;

import java.io.*;

import static java.lang.System.*;

public class kongge {

public static void main(String args[]) {

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("F:\\ww.python\\kongge.py");
PyFunction func = (PyFunction) interpreter.get("kongge",
PyFunction.class);

String cc = "F:/ww.python/bingli.txt";
String dd = "F:/ww.python/w.txt";

PyObject pyobj = func.__call__(new PyString(cc), new PyString(dd));
// (new PyInteger(a), new PyInteger(b));
System.out.println("anwser = " + pyobj.toString());

// PyFunction func =
// (PyFunction)interpreter.get("kongbai",PyFunction.class);
//
// String url1 = "F:\\ww.python\\ss.txt";
// int i=Integer.parseInt(url1);
//
//
//
// String url2 = "F:\\ww.python\\wuwei.txt" ;
// int j=Integer.parseInt(url2);
//
// PyObject pyobj = func.__call__(new ,new );
// System.out.println("anwser = " + pyobj.toString());
}// main
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: