コード例 #1
0
 public PythonInterpreter(PyObject dict, PySystemState systemState) {
   if (dict == null) dict = new PyStringMap();
   if (systemState == null) {
     systemState = Py.getSystemState();
     if (systemState == null) systemState = new PySystemState();
   }
   module = new PyModule("main", dict);
   this.systemState = systemState;
   locals = module.__dict__;
   setState();
 }
コード例 #2
0
 protected void setState() {
   Py.setSystemState(systemState);
 }
コード例 #3
0
 /**
  * Get the value of a variable in the local namespace Value will be returned as an instance of the
  * given Java class. <code>interp.get("foo", Object.class)</code> will return the most appropriate
  * generic Java object.
  *
  * @param name the name of the variable
  * @param javaclass the class of object to return
  */
 public Object get(String name, Class javaclass) {
   return Py.tojava(locals.__finditem__(name.intern()), javaclass);
 }
コード例 #4
0
 /**
  * Set a variable in the local namespace
  *
  * @param name the name of the variable
  * @param value the value to set the variable to. Will be automatically converted to an
  *     appropriate Python object.
  */
 public void set(String name, Object value) {
   locals.__setitem__(name.intern(), Py.java2py(value));
 }
コード例 #5
0
 public void execfile(java.io.InputStream s, String name) {
   setState();
   Py.runCode(Py.compile_flags(s, name, "exec", cflags), locals, locals);
 }
コード例 #6
0
 /**
  * Execute a Python code object in the local namespace
  *
  * @param code the code object to execute
  */
 public void exec(PyObject code) {
   setState();
   Py.exec(code, locals, locals);
 }
コード例 #7
0
 /**
  * Execute a string of Python source in the local namespace
  *
  * @param s the string to execute
  */
 public void exec(String s) {
   setState();
   Py.exec(Py.compile_flags(s, "<string>", "exec", cflags), locals, locals);
 }