r/Python • u/martinsa24 • Oct 23 '14
[Help]How to call Java .class methods in Python
I am working on a project where a I wrote a program in a in Java and made the GUI in python, buy now I want to know how to connect the two. Like calling my java methods in python, or running my python code in java.
Is there a program or lib to do this, or will I have to just translate my work into java or python.
Sorry if formatting is weird on my phone.
1
u/romcgb Oct 23 '14
1
u/mebimage Oct 23 '14 edited Oct 23 '14
Jython can't load CPython modules (such as PyQt or PyGTK) and doesn't have
tkinter. OP might be able to rig up some CPython+Jython monstrosity using XML-RPC if they really wanted to.EDIT: I think /u/inclemnet has the right answer.
0
u/nomadismydj Oct 23 '14
this is correct. unless you want to right a transport for the two to talk. (or access via jconsole.. which is not a great approach)
2
u/inclemnet Oct 23 '14
You can use pyjnius to work with java classes from python. It works fine from normal python, no special interpreter or anything. For example, Kivy uses it to call the android java api from python apps.
It does have some limitations and annoyances. Whether these are significant to you depends on your project, they may well not be.
There are also other similar projects, including at least jpype, but I don't know much about these.