简体   繁体   English

我可以使用Jython将Java库与我的Python代码链接吗

[英]Can I link a Java library using Jython with my code in Python

I need to use the library Jena which is in Java in my code that is written in Python. 我需要在用Python编写的代码中使用Java中的Jena库。 Now, I want to know if Jython can bridge between these two or not!!! 现在,我想知道Jython是否可以在这两者之间架起桥梁!!! according to this thread Jython can be invoked in a python code. 根据此线程,可以在python代码中调用Jython。 but I need to access the functions in Jena and get back the answers into my python code. 但是我需要访问耶拿(Jena)中的函数,并将答案返回到我的python代码中。 I am speculating that the code should look like below. 我推测代码应如下所示。 the main part is the importing a java library, running the desired function and getting the results back. 主要部分是导入Java库,运行所需的函数并将结果返回。

import execnet
gw = execnet.makegateway("popen//python=jython", var1, var2)
channel = gw.remote_exec("""
import Jena #it is a java library.
reason(var1, var2)
...
""")
fun(channel)

Yes, in principal you can take your existing Python code, import some Java libs into it, and then run it under Jython and it will work. 是的,原则上,您可以采用现有的Python代码,将一些Java库导入其中,然后在Jython下运行它,它将起作用。 That said, not all Python packages will work under Jython for various reasons, often due to C extensions or other differences in the implementation of the Jython interpreter from regular CPython. 就是说,由于各种原因,并不是所有的Python软件包都可以在Jython下工作,这通常是由于C扩展或常规CPython在Jython解释器的实现上存在其他差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM