I am wondering if it is possible to call Python functions from Java code using Jython, or is it only for calling Java code from Python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Jython: Python for the Java Platform – http://www.jython.org/index.html
You can easily call python functions from Java code with Jython. That is as long as your python code itself runs under jython, i.e. doesn’t use some c-extensions that aren’t supported.
If that works for you, it’s certainly the simplest solution you can get. Otherwise you can use
org.python.util.PythonInterpreterfrom the new Java6 interpreter support.A simple example from the top of my head – but should work I hope: (no error checking done for brevity)
As of 2021, Jython does not support Python 3.x