Apologies if my question is noob. I'm running Django 1.2 with pgsql 8.4 and I'm required to run a Java program after getting the inputs from the user, does some calculations and return the results back to the user.
May I know what is the best way to pass data between the Java and Python Django, such that the above scenario are taken care of? I heard of Jython, but according to the Django docs, it requires the extension jython-Django, but currently it doesn't support django 1.2.x. Should I pass the data using stdout?
thanks people for hearing me out.
So here we use JSON to communicate between two programs called Python and Java.
The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.
There are two options for communicating information from a Python process to a Java process: Java's popular networking libraries will make it easy to read in data through a socket. Since you can easily open up a socket in Python, implementing socket communication would be the easiest solution.
javabridge. CPython, that can be used to execute Python code. The class can be used within Java code called from the Python interpreter or it can be used within Java to run Python embedded in Java. The CPython class binds the Python interpreter to the JVM and provides the ability to execute Python scripts.
If all you are doing is calling Java for some calculations, then subprocess is the easiest way, but I just wanted to throw another option out there.
JPype is a package that lets you run a JVM inside your Python program while calling the Java code as if it were Python (example).
That is, it's like Jython in that you call Java code directly and like subprocess in that you are actually running CPython. Consider JPype if for some reason the Java code is not easy to call from a shell script (aka, subprocess) or if a lot of two-way communication is necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With