当前位置: 首页>>代码示例>>Java>>正文


Java PythonInterpreter.eval方法代码示例

本文整理汇总了Java中org.python.util.PythonInterpreter.eval方法的典型用法代码示例。如果您正苦于以下问题:Java PythonInterpreter.eval方法的具体用法?Java PythonInterpreter.eval怎么用?Java PythonInterpreter.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.python.util.PythonInterpreter的用法示例。


在下文中一共展示了PythonInterpreter.eval方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_jython_loading

import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
@Test
public void test_jython_loading() throws Throwable {
  CodeLoader loader = new CodeLoader();
  PythonInterpreter interpreter = loader.jython("check");

  PyObject object = interpreter.get("truth");
  assertTrue(object instanceof PyFunction);
  PyFunction fun = (PyFunction) object;
  assertEquals(new PyInteger(42), fun.__call__());

  object = interpreter.get("incr");
  assertTrue(object instanceof PyFunction);
  fun = (PyFunction) object;
  assertEquals(new PyInteger(3), fun.__call__(new PyInteger(2)));

  fun = (PyFunction) interpreter.get("foo");
  interpreter.exec("from org.gololang.microbenchmarks.support import Foo");
  PyObject foo = interpreter.eval("Foo()");
  assertEquals(new PyString("foo"), fun.__call__(foo));
}
 
开发者ID:golo-lang,项目名称:golo-jmh-benchmarks,代码行数:21,代码来源:CodeLoaderTest.java

示例2: main

import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
/**
 * Main entrypoint.
 *
 * @param args arguments
 * @throws ScriptException ScriptException
 */
public static void main(final String[] args) throws ScriptException {
  listEngines();

  // Integrate with ScriptEngine
  {
    final ScriptEngineManager mgr = new ScriptEngineManager();
    final ScriptEngine pyEngine = mgr.getEngineByName("python");

    try {
      pyEngine.eval("print \"Python - Hello, world!\"");
    } catch (ScriptException ex) {
      ex.printStackTrace();
    }
  }

  final PythonInterpreter interpreter = new PythonInterpreter();
  interpreter.exec("print \"Python - Hello, world!\"");

  PyObject result = interpreter.eval("2 + 3");
  System.out.println(result.toString());

  // Define a function and call it from Java
  interpreter.exec("def myLowerCase(s):\n\treturn s.lower()\n");
  final PyObject myLowerCase = interpreter.get("myLowerCase");
  result = myLowerCase.__call__(new PyString("TEST!"));
  final String realResult = (String)result.__tojava__(String.class);
  System.out.println(realResult);
}
 
开发者ID:soulmachine,项目名称:JythonExample,代码行数:35,代码来源:JythonExample.java

示例3: executePython

import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
/**
 * 执行指定的python文件
 * @param filePath
 * @return
 */
private PyObject executePython(String filePath){
	PythonInterpreter interpreter = new PythonInterpreter();
	Vector<AndroidDriver> drivers = new Vector();
	drivers.add(this);
	interpreter.set("device", drivers);
	interpreter.execfile(filePath);
	PyObject ret = interpreter.eval("True");
	return ret;
}
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:15,代码来源:AndroidDriver.java

示例4: evaluatePythonExpression

import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
private boolean evaluatePythonExpression(Row r, PyCode code, PythonInterpreter interpreter) {
	evalColumns.clear();
	try {
		ArrayList<Node> nodes = new ArrayList<Node>(r.getNodes());
		Node node = nodes.get(0);
		interpreter.getLocals().__setitem__("nodeid", new PyString(node.getId()));
		PyObject output = interpreter.eval(code);
		return PythonTransformationHelper.getPyObjectValueAsBoolean(output);
	}catch(Exception e) {
		return onError;
	}

}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:14,代码来源:MiniSelection.java


注:本文中的org.python.util.PythonInterpreter.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。