「java引用python」java引用值类型
今天给各位分享java引用python的知识,其中也会对java引用值类型进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、怎么使用java运行python脚本?
- 2、如何在Java中调用Python代码
- 3、eclipse中 java程序怎样调用python
- 4、java怎么点用python脚本?
- 5、用java执行python
- 6、Java如何调用Python的jar包?
怎么使用java运行python脚本?
如果是jython,也就是运行在Jvm上的python的话,可以使用JSR223,JDK1.6已经包含了该扩展包。JSR223是一个用于解析多种脚本语言的库包,其中包括Jython。除了JSR223包之外,还需要jython-engine.jar包。
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
try
{
engine.eval(new FileReader("./script/listing.py"));
}
catch(ScriptException se)
{
}
catch(IOException ie)
{
}
或者参考:
很久之前用过ScriptEngine,对在Jvm上的脚本语言比如jruby,jython,groovy等支持性都很好,有点忘记了。
如何在Java中调用Python代码
方法如下:
package com.lyz.test.jython;
import org.python.util.PythonInterpreter;
/**
* 第一个Jython程序
* @author liuyazhuang
*
*/
public class FirstJythonScript {
public static void main(String args[]) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days[1];");
}
}
eclipse中 java程序怎样调用python
方法如下:
package com.lyz.test.jython;
import org.python.util.PythonInterpreter;
/**
* 第一个Jython程序
* @author liuyazhuang
*
*/
public class FirstJythonScript {
public static void main(String args[]) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days[1];");
}
}
java怎么点用python脚本?
首先得声明一下,java是java,python是python,你用java得环境跑python这不是找麻烦吗,但是并不是说不行,java有一个Jpython得库,你可以下载一下,这方面原理设计jni技术,建议了解一下,如果单纯想运行一个脚本可以找Jpython得api文档看看
用java执行python
1.直接执行Python脚本代码
引用 org.python包
1 PythonInterpreter interpreter = new PythonInterpreter();
2 interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); "); ///执行python脚本
2. 执行python .py文件
1 PythonInterpreter interpreter = new PythonInterpreter();
2 InputStream filepy = new FileInputStream("D:\\demo.py");
3 interpreter.execfile(filepy); ///执行python py文件
4 filepy.close();
3. 使用Runtime.getRuntime()执行脚本文件
这种方式和.net下面调用cmd执行命令的方式类似。如果执行的python脚本有引用第三方包的,建议使用此种方式。使用上面两种方式会报错java ImportError: No module named arcpy。
1 Process proc = Runtime.getRuntime().exec("python D:\\demo.py");
2 proc.waitFor();
Java如何调用Python的jar包?
Python - Native 代码 整体思路 先将Python 源代码转换成 C 代码,之后用 GCC 编译 C 代码为二进制模块 so/dll,接着进行一次 Java Native 接口封装,
java引用python的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java引用值类型、java引用python的信息别忘了在本站进行查找喔。
发布于:2022-12-06,除非注明,否则均为
原创文章,转载请注明出处。