KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SimpleEmbedded


1 import org.python.util.PythonInterpreter;
2 import org.python.core.*;
3
4 public class SimpleEmbedded {
5     public static void main(String JavaDoc []args) throws PyException {
6         PythonInterpreter interp = new PythonInterpreter();
7
8         System.out.println("Hello, brave new world");
9         interp.exec("import sys");
10         interp.exec("print sys");
11
12         interp.set("a", new PyInteger(42));
13         interp.exec("print a");
14         interp.exec("x = 2+2");
15         PyObject x = interp.get("x");
16
17         System.out.println("x: "+x);
18         System.out.println("Goodbye, cruel world");
19     }
20 }
Popular Tags