org.python.util.PythonInterpreter.setLocals()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.python.util.PythonInterpreter.setLocals()方法的一些代码示例,展示了PythonInterpreter.setLocals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PythonInterpreter.setLocals()方法的具体详情如下:
包路径:org.python.util.PythonInterpreter
类名称:PythonInterpreter
方法名:setLocals

PythonInterpreter.setLocals介绍

暂无

代码示例

代码示例来源:origin: io.openscore.lang/score-lang-runtime

private void cleanInterpreter(PythonInterpreter interpreter) {
    interpreter.setLocals(new PyStringMap());
  }
}

代码示例来源:origin: io.cloudslang/runtime-management-impl

private void initInterpreter() {
  interpreter.setLocals(new PyStringMap());
}

代码示例来源:origin: CloudSlang/score

private void initInterpreter() {
  interpreter.setLocals(new PyStringMap());
}

代码示例来源:origin: org.python/jython

throw new IllegalArgumentException("interface expected");
interp.setLocals(new PyScriptEngineScope(this, context));
final PyObject thiz = Py.java2py(obj);
@SuppressWarnings("unchecked")

代码示例来源:origin: org.python/jython

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
      interp.setLocals(new PyScriptEngineScope(PyScriptEngine.this, context));
      PyObject pyMethod = thiz.__findattr__(method.getName());
      if (pyMethod == null)
        throw new NoSuchMethodException(method.getName());
      PyObject result;
      if(args != null) {
        result = pyMethod.__call__(Py.javas2pys(args));
      } else {
        result = pyMethod.__call__();
      }
      return result.__tojava__(Object.class);
    } catch (PyException pye) {
      throw scriptException(pye);
    }
  }
});

代码示例来源:origin: usc-isi-i2/Web-Karma

public void initializeInterpreter(PythonInterpreter interpreter)
{
  boolean localsUninitialized = interpreter.getLocals() == initialLocals;
  if(localsUninitialized)
  {
    PyStringMap locals = new PyStringMap();
    interpreter.setLocals(locals);
    interpreter.exec(scripts.get(PythonTransformationHelper.getImportStatements()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getGetValueDefStatement()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getIsEmptyDefStatement()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getHasSelectedRowsStatement()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getGetValueFromNestedColumnByIndexDefStatement()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getRowIndexDefStatement()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getVDefStatement()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getModelName()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getModelPrefix()));
    interpreter.exec(scripts.get(PythonTransformationHelper.getModelBaseUri()));
    
  }
  if(localsUninitialized ||(!libraryHasBeenLoaded || reloadLibrary))
  {
    importUserScripts(interpreter);
  }
}

代码示例来源:origin: org.python/jython

public Object invokeFunction(String name, Object... args) throws ScriptException,
    NoSuchMethodException {
  try {
    interp.setLocals(new PyScriptEngineScope(this, context));
    PyObject function = interp.get(name);
    if (function == null) {
      throw new NoSuchMethodException(name);
    }
    PyObject result;
    if(args != null) {
      result = function.__call__(Py.javas2pys(args));
    } else {
      result = function.__call__();
    }
    return result.__tojava__(Object.class);
  } catch (PyException pye) {
    throw scriptException(pye);
  }
}

代码示例来源:origin: org.python/jython

public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException,
    NoSuchMethodException {
  try {
    interp.setLocals(new PyScriptEngineScope(this, context));
    if (!(thiz instanceof PyObject)) {
      thiz = Py.java2py(thiz);
    }
    PyObject method = ((PyObject) thiz).__findattr__(name);
    if (method == null) {
      throw new NoSuchMethodException(name);
    }
    //return method.__call__(Py.javas2pys(args)).__tojava__(Object.class);
    PyObject result;
    if(args != null) {
      result = method.__call__(Py.javas2pys(args));
    } else {
      result = method.__call__();
    }
    return result.__tojava__(Object.class);
  } catch (PyException pye) {
    throw scriptException(pye);
  }
}

代码示例来源:origin: org.python/jython

private Object eval(PyCode code, ScriptContext context) throws ScriptException {
  try {
    interp.setIn(context.getReader());
    interp.setOut(context.getWriter());
    interp.setErr(context.getErrorWriter());
    interp.setLocals(new PyScriptEngineScope(this, context));
    return interp.eval(code).__tojava__(Object.class);
  } catch (PyException pye) {
    throw scriptException(pye);
  }
}

相关文章