这是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
}
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
}