Python之玩转Jython系列(一)
来源:互联网 发布:域名备案注销 编辑:程序博客网 时间:2024/05/21 16:11
,java 调用jython
简单调用:
PythonInterpreter interp1 = new PythonInterpreter();interp1.exec("import re");interp1.execfile("./src/com/configValue.py");PyFunction pyFunction1 = (PyFunction) interp1.get("jython里的方法名",PyFunction.class);System.out.println("config value: "+ pyFunction1.__call__(new PyString("MaxValue")));
但在项目中,这样会带来很多麻烦,特此修改了下,如下:
PythonInterpreter interp = new PythonInterpreter();Map<PyObject, PyObject> bean = new HashMap<PyObject, PyObject>(); //取得根目录路径 String rootPath=getClass().getResource("../").getFile().toString(); String path = rootPath + "xxx/xxx.py"; interp.execfile(path);PyFunction func = interp.get("jython里的方法名", PyFunction.class);bean.put(new PyString("key"),PyJavaType.wrapJavaObject(jythonMethod));PyDictionary pyDictionary = new PyDictionary(bean);obj = func.__call__(pyDictionary);return obj;这样的话,就可以调用到对应的jython了
0 0
- Python之玩转Jython系列(一)
- Python之玩转Jython系列(二)
- Redis系列之(一):10分钟玩转Redis
- Docker系列之(一):10分钟玩转Docker
- Docker系列之(一):10分钟玩转Docker
- Redis系列之10分钟玩转Redis(一):
- jython学习笔记(一)-----Java调用python
- Jython & Python
- <IT基础复习系列1之玩转Spring>Spring基础之高效学习(一)
- Jython-Java操作Python脚本学习笔记(一)
- 上课不听讲下课来补习系列之-玩转单片机STM8(一)
- Python系列之 - python数据类型(一)
- Python系列(一)之Python基础
- Jython & Python Examples
- python vs jython
- Jython 和 Python 对比
- Python Jython 记录 ImportError
- jython源码一例
- Windows下编译FFmpeg详解
- 编程珠玑-随机抽样
- 数据库的查询,关于时间的情况
- Repeater中绑定的LinkButton跳转页面及传递参数
- ListView性能优化
- Python之玩转Jython系列(一)
- 静态方法与实例方法共享设计-jquery学习笔记
- 读《程序员编程艺术》之自造Java版本-----插入排序实现最小K问题
- leetcode || 75、Sort Colors
- 看数据结构写代码(37) 图的十字链表的表示与实现
- IOS 多线程原理
- TRANCE宏的利用
- 构建源码树----Linux内核剖析(三)
- 两种快速排序算法性能的比较