java引用jpython的方法示例
更新時間:2016年11月04日 11:52:01 作者:yczz
這篇文章主要介紹了java引用jpython的方法,結(jié)合實例形式分析了java引用jpython及相關(guān)使用技巧,需要的朋友可以參考下
本文實例講述了java引用jpython的方法。分享給大家供大家參考,具體如下:
import java.util.ArrayList;
import java.util.List;
import org.python.core.PyException;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class python {
public static void main(String []args)throws PyException
{
PythonInterpreter interp =new PythonInterpreter();
System.out.println("Hello, brave new world");
interp.exec("import sys");
interp.exec("print sys");
interp.set("a", new PyInteger(42));
interp.exec("print 'test='+str(a)");
interp.exec("x = 2+2");
PyObject x = interp.get("x");
System.out.println("x: "+x);
System.out.println("Goodbye, cruel world");
interp.exec("import re");
//interp.exec("print dir(re)");
interp.exec("t =re.compile('^(0{2}):(IFCSUM):(MANIFEST):')");
interp.exec(" a = t.search('00:IFCSUM:MANIFEST:').groups()");
PyObject k = interp.get("a");
List list = ((List)k.__tojava__(List.class));
// int ai= ((Integer)a.__tojava__(Integer.class)).intValue();
System.out.println(k);
System.out.println(list);
}
}
希望本文所述對大家java程序設(shè)計有所幫助。
您可能感興趣的文章:
相關(guān)文章
圖解Eclipse j2ee開發(fā)環(huán)境的搭建過程
這篇文章以圖文結(jié)合的方式介紹了Eclipse j2ee開發(fā)環(huán)境的搭建過程,內(nèi)容很詳細(xì),每一個步驟都有對應(yīng)的操作截圖,需要的朋友可以參考下2015-08-08
idea創(chuàng)建springboot項目,Application.java不能運(yùn)行問題及解決
這篇文章主要介紹了idea創(chuàng)建springboot項目,Application.java不能運(yùn)行問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11
深入了解Springboot核心知識點之?dāng)?shù)據(jù)訪問配置
這篇文章主要為大家介紹了Springboot核心知識點中的數(shù)據(jù)訪問配置,文中的示例代碼講解詳細(xì),對我們了解SpringBoot有一定幫助,快跟隨小編一起學(xué)習(xí)一下吧2021-12-12
利用Lambda表達(dá)式創(chuàng)建新線程案例
這篇文章主要介紹了利用Lambda表達(dá)式創(chuàng)建新線程案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08

