Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

I think there are some important things to consider first with how strong you wish to have the linking between javaJava and pythonPython.

Firstly Do you only want to call functions or do you actually want pythonPython code to change the data in your java objects? This is very important. If you only want to call some pythonPython code with or without arguments, then that is not very difficult. If your arguments are primitives it makes it even more easy. However, if you want to have javaJava class implement member functions in pythonPython, which change the data of the javaJava object, then this is not so easy or straight forward.

Secondly are we talking cpythonCPython, or will jythonJython do? I would say cpythonCPython is where its at! I would advocate this is why pythonPython is so kool! Having such high abstractions however access to c,c++C or C++ when needed. Imagine if you could have that in javaJava. This question is not even worth asking if jythonJython is ok because then it is easy anyway.

Advantages: Trivially easy. Have actual references to javaJava objects

Jython from javaJava is so easy, and if this is really enough then great. However it is very slow and no cpythonCPython! Is life worth living without cpythonCPython? I don't think so! You can easily have pythonPython code implementing your member functions for you javaJava objects.

Pyro is the remote object module for pythonPython. You have some object on a cpythonCPython interpreter, and you can send it objects which are transferred via serialization and it can also return objects via this method. Note that if you send a serialized pythonPython object from jythonJython and then call some functions which change the data in its members, then you will not see those changes in javaJava. You just need to remember to send back the data which you want from pyroPyro. This, I believe, is the easiest way to get to cpythonCPython! You do not need any jniJNI or jnaJNA or swigSWIG or .... You don't need to know any cC, or c++C++. koolKool huh?

Advantages: Access to cpython, not as difficult as following methods

  • Access to CPython
  • Not as difficult as following methods

Disadvantages: Cannot change the member data of java objects directly from python. Is somewhat indirect, (jython is middle man).

  • Cannot change the member data of Java objects directly from Python
  • Is somewhat indirect (Jython is middle man)

OMG this method is not for the faint of heart. And I can tell you it has taken me very long to achieve this in with a decent method. Main reason you would want to do this is so that you can run cpythonCPython code which as full rein over you java object. There are major major major things to consider before deciding to try and bread javabreed Java (which is like a chimp) with pythonPython (which is like a horse). Firstly if you crash the interpreter, that's lights out for you program! And don't get me started on concurrency issues! In addition, there is allot allota lot of boiler, I believe I have found the best configuration to minimize this boiler but still it is allotstill a lot! So how to go about this: Consider that C++ is your middle man, your objects are actually c++C++ objects! Good that you know that now. Just write your object as if your program asis in cppC++ and not javaJava, with the data you want to access from both worlds. Then you can use the wrapper generator called swig (http://www.swig.org/Doc1.3/Java.htmlSWIG) to make this accessible to java and compile a dll which you call System.load(dll name hereSystem.load(dllNameHere)) in javaJava. Get this working first, then move on to the hard part! To get to pythonPython you need to embed an interpreter. Firstly I suggest doing some hello interpreter programs or this tutorial Embedding pythonPython in C/C. Once you have that working, its time to make the horse and the monkey dance! You can send you c++C++ object to pythonPython via [boost][3] . I know I have not given you the fish, merely told you where to find the fish. Some pointers to note for this when compiling.

I think there are some important things to consider first with how strong you wish to have the linking between java and python.

Firstly Do you only want to call functions or do you actually want python code to change the data in your java objects? This is very important. If you only want to call some python code with or without arguments, then that is not very difficult. If your arguments are primitives it makes it even more easy. However if you want to have java class implement member functions in python, which change the data of the java object, then this is not so easy or straight forward.

Secondly are we talking cpython or will jython do? I would say cpython is where its at! I would advocate this is why python is so kool! Having such high abstractions however access to c,c++ when needed. Imagine if you could have that in java. This question is not even worth asking if jython is ok because then it is easy anyway.

Advantages: Trivially easy. Have actual references to java objects

Jython from java is so easy, and if this is really enough then great. However it is very slow and no cpython! Is life worth living without cpython I don't think so! You can easily have python code implementing your member functions for you java objects.

Pyro is the remote object module for python. You have some object on a cpython interpreter, and you can send it objects which are transferred via serialization and it can also return objects via this method. Note that if you send a serialized python object from jython and then call some functions which change the data in its members, then you will not see those changes in java. You just need to remember to send back the data which you want from pyro. This I believe is the easiest way to get to cpython! You do not need any jni or jna or swig or .... You don't need to know any c, or c++. kool huh?

Advantages: Access to cpython, not as difficult as following methods

Disadvantages: Cannot change the member data of java objects directly from python. Is somewhat indirect, (jython is middle man).

OMG this method is not for the faint of heart. And I can tell you it has taken me very long to achieve this in with a decent method. Main reason you would want to do this is so that you can run cpython code which as full rein over you java object. There are major major things to consider before deciding to try and bread java (which is like a chimp) with python (which is like a horse). Firstly if you crash the interpreter that's lights out for you program! And don't get me started on concurrency issues! In addition, there is allot allot of boiler, I believe I have found the best configuration to minimize this boiler but still it is allot! So how to go about this: Consider that C++ is your middle man, your objects are actually c++ objects! Good that you know that now. Just write your object as if your program as in cpp not java, with the data you want to access from both worlds. Then you can use the wrapper generator called swig (http://www.swig.org/Doc1.3/Java.html) to make this accessible to java and compile a dll which you call System.load(dll name here) in java. Get this working first, then move on to the hard part! To get to python you need to embed an interpreter. Firstly I suggest doing some hello interpreter programs or this tutorial Embedding python in C/C. Once you have that working, its time to make the horse and the monkey dance! You can send you c++ object to python via [boost][3] . I know I have not given you the fish, merely told you where to find the fish. Some pointers to note for this when compiling.

I think there are some important things to consider first with how strong you wish to have the linking between Java and Python.

Firstly Do you only want to call functions or do you actually want Python code to change the data in your java objects? This is very important. If you only want to call some Python code with or without arguments, then that is not very difficult. If your arguments are primitives it makes it even more easy. However, if you want to have Java class implement member functions in Python, which change the data of the Java object, then this is not so easy or straight forward.

Secondly are we talking CPython, or will Jython do? I would say CPython is where its at! I would advocate this is why Python is so kool! Having such high abstractions however access to C or C++ when needed. Imagine if you could have that in Java. This question is not even worth asking if Jython is ok because then it is easy anyway.

Advantages: Trivially easy. Have actual references to Java objects

Jython from Java is so easy, and if this is really enough then great. However it is very slow and no CPython! Is life worth living without CPython? I don't think so! You can easily have Python code implementing your member functions for you Java objects.

Pyro is the remote object module for Python. You have some object on a CPython interpreter, and you can send it objects which are transferred via serialization and it can also return objects via this method. Note that if you send a serialized Python object from Jython and then call some functions which change the data in its members, then you will not see those changes in Java. You just need to remember to send back the data which you want from Pyro. This, I believe, is the easiest way to get to CPython! You do not need any JNI or JNA or SWIG or .... You don't need to know any C, or C++. Kool huh?

Advantages:

  • Access to CPython
  • Not as difficult as following methods

Disadvantages:

  • Cannot change the member data of Java objects directly from Python
  • Is somewhat indirect (Jython is middle man)

OMG this method is not for the faint of heart. And I can tell you it has taken me very long to achieve this in with a decent method. Main reason you would want to do this is so that you can run CPython code which as full rein over you java object. There are major things to consider before deciding to try and breed Java (which is like a chimp) with Python (which is like a horse). Firstly if you crash the interpreter, that's lights out for you program! And don't get me started on concurrency issues! In addition, there is a lot of boiler, I believe I have found the best configuration to minimize this boiler but it is still a lot! So how to go about this: Consider that C++ is your middle man, your objects are actually C++ objects! Good that you know that now. Just write your object as if your program is in C++ and not Java, with the data you want to access from both worlds. Then you can use the wrapper generator called SWIG to make this accessible to java and compile a dll which you call (System.load(dllNameHere)) in Java. Get this working first, then move on to the hard part! To get to Python you need to embed an interpreter. Firstly I suggest doing some hello interpreter programs or this tutorial Embedding Python in C/C. Once you have that working, its time to make the horse and the monkey dance! You can send you C++ object to Python via [boost][3] . I know I have not given you the fish, merely told you where to find the fish. Some pointers to note for this when compiling.

deleted 29 characters in body
Source Link
Dharman
  • 34k
  • 27
  • 106
  • 157

Hey I thought I would enter my answer to this even though its late. I think there are some important things to consider first with how strong you wish to have the linking between java and python.

Hey I thought I would enter my answer to this even though its late. I think there are some important things to consider first with how strong you wish to have the linking between java and python.

I think there are some important things to consider first with how strong you wish to have the linking between java and python.

Commonmark migration
Source Link
Source Link
Derrops
  • 8.2k
  • 7
  • 39
  • 75
Loading