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
}
相关文章推荐
- Python的哪些特性或用法让你相见恨晚?
- Python中的装饰器decorator
- Python shutil模块
- python开发_xml.etree.ElementTree_XML文件操作_该模块在操作XML数据是存在安全隐患_慎用
- pylearn2 安装及测试 windows 7 64bit
- python正则表达式
- python关于 date的使用
- winpython安装
- python+Eclipse+pydev环境搭建
- 为什么学习Python
- 初识Python
- opencv + numpy for python
- Python实现plist图片的裁切
- python 学习笔记(07)
- python fabric实现远程操作和部署
- 如何面试Python后端工程师?
- 【window10下notepad++编程软件配置python编程环境详细图文教程】
- python实现逻辑回归
- python学习
- vim 创建Python脚本时候自动补全解释器和编码方法