当前位置:编程学堂 > idea java调用python代码

idea java调用python代码

  • 发布:2023-09-09 17:38

public static void demo01() throws Exception{System.out.println("java ___________________________");Process process = Runtime.getRuntime().exec("py E:\\java_project\\database01\\src\\main\\java\\www.sychzs.cn");BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));String line ;while ((line = in.readLine()) != null) {System.out.println(line);}in.close();process.waitFor();System.out.println("end ");} 首先需要在maven中添加依赖 org.pythonjython-standalone2.7.0 运行代码 public static String getIncodePass(String cellphone) throws Exception{PythonInterpreter pythonInterpreter = new PythonInterpreter();pythonInterpreter.execfile("E:\\java_project\\database01\\src\\main\\java\\www.sychzs.cn");PyFunction pyFunction = pythonInterpreter.get("generate_pwd", PyFunction.class);PyObject pyObject = pyFunction.__call__(new PyString(demo02(cellphone)));return pyObject.toString();} 目前存在的疑问主要有以下两点 1.利用Java代码通过本地环境运行python代码不知道如何实现参数传递?例如:在Java代码中设置一个字符串参数,如何传递到.py文件的函数方法中执行得到结果 2.利用通过PythonInterpreter如何加载第三方库,包等? 欢迎各位知道解决方法的小伙伴积极留言,感谢

相关文章

热门推荐