1.首先在官网下载
https://www.jython.org/download

2.jar包下载后将其拖入lib文件


如果你没有的话,可以在src目录下建一个folder文件,名字为lib
3.项目导入jar包:https://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html
项目右键->build path->config build path

4.代码
import org.python.util.PythonInterpreter;
public class java_python {
public static void main(String[] args) {
// System.out.println("hello word");
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("a=[5,2,3,9,4,0]; ");
interpreter.exec("print(sorted(a));"); //此处python语句是3.x版本的语法
interpreter.exec("print sorted(a);"); //此处是python语句是2.x版本的语法
}
}

被折叠的 条评论
为什么被折叠?



