0

I need to use the library Jena which is in Java in my code that is written in Python. Now, I want to know if Jython can bridge between these two or not!!! according to this thread Jython can be invoked in a python code. but I need to access the functions in Jena and get back the answers into my python code. 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.

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)
Community
  • 1
  • 1
msc87
  • 943
  • 3
  • 17
  • 39
  • 1
    Could you provide an example, in code, of what you want to do? Are you trying to use both CPython and Jython simultaneously? – davidrmcharles Jul 10 '15 at 15:33
  • @DavidCharles: that is the question. I have a code in python and a library in Java. now I want to use the library in my code. how can I use it? Is Jython the solution in some way or there is no way that I can integrate them? – msc87 Jul 13 '15 at 11:42

1 Answers1

0

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. 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.

Robin Davis
  • 622
  • 4
  • 10