Python在Java中的应用效果

发布时间:2021-08-25 15:31:41 作者:chen
来源:亿速云 阅读:86

本篇内容主要讲解“Python在Java中的应用效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python在Java中的应用效果”吧!

python.java   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("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));   //System.out.println(k);   System.out.println(list);   }   }

到此,相信大家对“Python在Java中的应用效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. redis在java web中的应用
  2. 类在java中的应用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python java

上一篇:Python多线程具体应用的方法

下一篇:MyBatis如何实现分库分表

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》