Java調(diào)用python的方法(jython)
1 什么是jython?
他其實(shí)是一門語(yǔ)言,并非是Java 或者Python的解釋器.用它可以實(shí)現(xiàn),java和python代碼的互相訪問(wèn)。
2 簡(jiǎn)單的例子
java中執(zhí)行python 語(yǔ)句
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類當(dāng)中的函數(shù)
先在python文件中定一個(gè)python函數(shù)
def pluser(a,b): # print "the result of pluser is %d" % (a+b) return a+b
在java當(dāng)中去調(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));
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解SpringMVC和MyBatis框架開發(fā)環(huán)境搭建和簡(jiǎn)單實(shí)用
這篇文章主要介紹了詳解SpringMVC和MyBatis框架開發(fā)環(huán)境搭建和簡(jiǎn)單實(shí)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
RestTemplate get請(qǐng)求攜帶headers自動(dòng)拼接參數(shù)方式
這篇文章主要介紹了RestTemplate get請(qǐng)求攜帶headers自動(dòng)拼接參數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
詳解Spring Boot實(shí)戰(zhàn)之Filter實(shí)現(xiàn)使用JWT進(jìn)行接口認(rèn)證
本篇文章主要介紹了詳解Spring Boot實(shí)戰(zhàn)之Filter實(shí)現(xiàn)使用JWT進(jìn)行接口認(rèn)證,具有一定的參考價(jià)值,有興趣的可以了解一下2017-07-07
Springboot整合GuavaCache緩存過(guò)程解析
這篇文章主要介紹了springboot整合GuavaCache緩存過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02
SpringBoot的啟動(dòng)過(guò)程源碼詳細(xì)分析
這篇文章主要介紹了SpringBoot的啟動(dòng)過(guò)程源碼詳細(xì)分析,SpringBoot啟動(dòng)的時(shí)候,會(huì)構(gòu)造一個(gè)SpringApplication的實(shí)例,構(gòu)造SpringApplication的時(shí)候會(huì)進(jìn)行初始化的工作,需要的朋友可以參考下2023-11-11

