Java調(diào)用python的方法(jython)
1 什么是jython?
他其實是一門語言,并非是Java 或者Python的解釋器.用它可以實現(xiàn),java和python代碼的互相訪問。
2 簡單的例子
java中執(zhí)行python 語句
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days;");
java調(diào)用python的腳本:
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("script.py");
java調(diào)用python類當中的函數(shù)
先在python文件中定一個python函數(shù)
def pluser(a,b): # print "the result of pluser is %d" % (a+b) return a+b
在java當中去調(diào)用:
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("F:\\machine learning\\machinelearninginaction\\Ch02\\test.py");
PyFunction function = (PyFunction)interpreter.get("pluser",PyFunction.class);
PyObject o = function.__call__(new PyInteger(8),new PyInteger(23));
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解SpringMVC和MyBatis框架開發(fā)環(huán)境搭建和簡單實用
這篇文章主要介紹了詳解SpringMVC和MyBatis框架開發(fā)環(huán)境搭建和簡單實用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05
RestTemplate get請求攜帶headers自動拼接參數(shù)方式
這篇文章主要介紹了RestTemplate get請求攜帶headers自動拼接參數(shù)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
詳解Spring Boot實戰(zhàn)之Filter實現(xiàn)使用JWT進行接口認證
本篇文章主要介紹了詳解Spring Boot實戰(zhàn)之Filter實現(xiàn)使用JWT進行接口認證,具有一定的參考價值,有興趣的可以了解一下2017-07-07

