`

java调用python

阅读更多
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);


       }
} 
分享到:
评论
4 楼 RonQi 2011-12-05  
lionkingzw 写道
pop1030123 写道
wly719 写道
java 中调用的python包在哪里下载?请告知下...


告知下...

楼主如果是转载的应该给出原始链接,应该是转载的这篇吧
http://bbs.chinaunix.net/viewthread.php?tid=1026375
找包的同学可以去搜一下Jython
3 楼 lionkingzw 2010-08-10  
pop1030123 写道
wly719 写道
java 中调用的python包在哪里下载?请告知下...


告知下...
2 楼 pop1030123 2010-02-10  
wly719 写道
java 中调用的python包在哪里下载?请告知下...

1 楼 wly719 2009-12-28  
java 中调用的python包在哪里下载?请告知下...

相关推荐

Global site tag (gtag.js) - Google Analytics