The example in this article describes the Java reference Jpython method. Share to everyone for your reference, specific as follows:
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 PYT
Honinterpreter ();
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);
}
}
I hope this article will help you with your Java programming.