Esempio n. 1
0
 /**
  * Convenience method for constructing a type object of a Python exception, named as given, and
  * added to the namespace of the "_io" module.
  *
  * @param dict module dictionary
  * @param excname name of the exception
  * @param bases one or more bases (superclasses)
  * @return the constructed exception type
  */
 private static PyType makeException(PyObject dict, String excname, PyObject... bases) {
   PyStringMap classDict = new PyStringMap();
   classDict.__setitem__("__module__", Py.newString("_io"));
   PyType type = (PyType) Py.makeClass(excname, bases, classDict);
   dict.__setitem__(excname, type);
   return type;
 }
Esempio n. 2
0
  public PyScriptEngine() {
    if (!initialized) {
      initializer();
      initialized = true;
    }

    // Set __name__ == "__main__" (useful for python scripting)
    // Without this, it is "__builtin__"
    PyStringMap dict = new PyStringMap();
    dict.__setitem__("__name__", new PyString("__main__"));

    // start with a fresh PySystemState
    PySystemState sys = new PySystemState();

    py = new PythonInterpreter(dict, sys);
  }