Calling Python in Java?

前端 未结 11 1256
北荒
北荒 2020-11-22 13:04

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?

11条回答
  •  死守一世寂寞
    2020-11-22 13:27

    It depends on what do you mean by python functions? if they were written in cpython you can not directly call them you will have to use JNI, but if they were written in Jython you can easily call them from java, as jython ultimately generates java byte code.

    Now when I say written in cpython or jython it doesn't make much sense because python is python and most code will run on both implementations unless you are using specific libraries which relies on cpython or java.

    see here how to use Python interpreter in Java.

提交回复
热议问题