发布于 2018-01-27 09:58:33 | 269 次阅读 | 评论: 1 | 来源: 网友投递

这里有新鲜出炉的Python多线程编程,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


这篇文章主要介绍了java引用jpython的方法,结合实例形式分析了java引用jpython及相关使用技巧,需要的朋友可以参考下

本文实例讲述了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程序设计有所帮助。



最新网友评论  共有(1)条评论 发布评论 返回顶部
素材火 发布于2018-01-27 10:10:25
来学习一下
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务