如何在Java中調(diào)用jython方法?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
10年積累的做網(wǎng)站、成都網(wǎng)站設(shè)計經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有潮陽免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
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));
關(guān)于如何在Java中調(diào)用jython方法問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
當前標題:如何在Java中調(diào)用jython方法
分享網(wǎng)址:http://aaarwkj.com/article40/iijheo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、網(wǎng)站營銷、品牌網(wǎng)站制作、網(wǎng)站收錄、App設(shè)計、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)