June 2002
Beginner to intermediate
640 pages
14h 24m
English
What follows is an example of embedding Jython in the Java code that ships with Jython's standard distribution. I've added comments.
import org.python.util.PythonInterpreter; import org.python.core.*; public class SimpleEmbedded { public static void main(String []args) throws PyException { // Create a Python interpreter. PythonInterpreter interp = new PythonInterpreter(); System.out.println("Hello, brave new world"); // Execute an import statement and a // print statement. interp.exec("import sys"); interp.exec("print sys"); // Create a variable by assigning // it the value 42. // PyInterger is a Python integer. interp.set("a", new PyInteger(42)); // Execute the print statement to // print out the value of a. interp.exec("print ...Read now
Unlock full access