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

Jython_Java 调用python

2012-07-18 11:17 190 查看
package com.android.example;

import com.google.common.base.Predicate;
import org.python.util.PythonInterpreter;

public class Main implements Predicate<PythonInterpreter> {
@Override
public boolean apply(PythonInterpreter anInterpreter) {

/*
* Examples of creating and initializing variables in the monkeyrunner environment's
* namespace. During execution, the monkeyrunner program can refer to the variables "newtest"
* and "use_emulator"
*
*/
anInterpreter.set("newtest", "enabled");
anInterpreter.set("use_emulator", 1);

return true;
}
}[/code]
使用java 调用PythonInterpreter

问题一:

import com.google.common.base.Predicate;
需要导入google-collections.jar包到java 工程中。(http://www.java2s.com/Code/Jar/g/Downloadgooglecollectionsjar.htm)

问题二:
import org.python.util.PythonInterpreter;

需要选择jython的安装路径(例如:C:\jython2.5.1),然后java工程导入jython.jar就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: