java引用jpython的方法示例
本文实例讲述了java引用jpython的方法。分享给大家供大家参考,具体如下:
importjava.util.ArrayList; importjava.util.List; importorg.python.core.PyException; importorg.python.core.PyInteger; importorg.python.core.PyObject; importorg.python.util.PythonInterpreter; publicclasspython{ publicstaticvoidmain(String[]args)throwsPyException { PythonInterpreterinterp=newPythonInterpreter(); System.out.println("Hello,bravenewworld"); interp.exec("importsys"); interp.exec("printsys"); interp.set("a",newPyInteger(42)); interp.exec("print'test='+str(a)"); interp.exec("x=2+2"); PyObjectx=interp.get("x"); System.out.println("x:"+x); System.out.println("Goodbye,cruelworld"); interp.exec("importre"); //interp.exec("printdir(re)"); interp.exec("t=re.compile('^(0{2}):(IFCSUM):(MANIFEST):')"); interp.exec("a=t.search('00:IFCSUM:MANIFEST:').groups()"); PyObjectk=interp.get("a"); Listlist=((List)k.__tojava__(List.class)); //intai=((Integer)a.__tojava__(Integer.class)).intValue(); System.out.println(k); System.out.println(list); } }
希望本文所述对大家java程序设计有所帮助。