Jython,一个JVM库,负责解释运行Python代码
https://www.jython.org/
首先看一个官方例子
- import org.python.util.PythonInterpreter;
-
- public class JythonHelloWorld {
- public static void main(String[] args) {
- try(PythonInterpreter pyInterp = new PythonInterpreter()) {
- pyInterp.exec("print('Hello Python World!')");
- }
- }
- }
看,我们的JVM可以执行Python代码了
第二个列子,Python代码里面直接调用Java的类库
- from java.lang import System # Java import
-
- print('Running on Java version: ' + System.getProperty('java.version'))
- print('Unix time from Java: ' + str(System.currentTimeMillis()))
有了这个利器,以后是不是可以早点下班了呢?