Calling Python in Java?

前端 未结 11 1366
北荒
北荒 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:29

    Jython has some limitations:

    There are a number of differences. First, Jython programs cannot use CPython extension modules written in C. These modules usually have files with the extension .so, .pyd or .dll. If you want to use such a module, you should look for an equivalent written in pure Python or Java. Although it is technically feasible to support such extensions - IronPython does so - there are no plans to do so in Jython.

    Distributing my Python scripts as JAR files with Jython?

    you can simply call python scripts (or bash or Perl scripts) from Java using Runtime or ProcessBuilder and pass output back to Java:

    Running a bash shell script in java

    Running Command Line in Java

    java runtime.getruntime() getting output from executing a command line program

提交回复
热议问题