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

Java调用Python(2.7.x)的简单示例

2014-09-19 17:20 609 查看
1. 新建工程,导入jython.jar,工程结构如图:



2. python脚本hello.py:

import time

print "Hello Jyhton!"
print time.asctime()


3. Java代码HelloJython.java:
package com.huey.dream.hello;

import org.python.util.PythonInterpreter;

/**
* Jython的简单示例
* @author  huey2672
* @version 1.0
* @created 2014-9-19
*/
public class HelloJython {
public static void main(String[] args) {

PythonInterpreter pyInterpreter = new PythonInterpreter();

pyInterpreter.execfile("script/py/hello.py");

pyInterpreter.exec("print '2 ** 3 =', 2 ** 3");

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