天天看点

java执行jython

import org.python.util.PythonInterpreter;

public class JythonHelloWorld
{
    public static void main(String[] args)
    {
        PythonInterpreter pyInterp = new PythonInterpreter();
        try
        {
            pyInterp.exec("print('Hello Python World!')");
        }
        finally
        {
            pyInterp.close();
        }
    }
}
           

PythonInterpreter是python解释器,需要下载jython-standalone-2.7.2.jar

Downloads | Jython