當前位置: 首頁>>代碼示例>>Java>>正文


Java PythonInterpreter.set方法代碼示例

本文整理匯總了Java中org.python.util.PythonInterpreter.set方法的典型用法代碼示例。如果您正苦於以下問題:Java PythonInterpreter.set方法的具體用法?Java PythonInterpreter.set怎麽用?Java PythonInterpreter.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.python.util.PythonInterpreter的用法示例。


在下文中一共展示了PythonInterpreter.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
/**
 * The main thread for this class invoked by Thread.run()
 *
 * @see java.lang.Thread#run()
 */
public void run() {
    PythonInterpreter p = new PythonInterpreter();
    for (String name : this.locals.keySet()) {
        p.set(name, this.locals.get(name));
    }

    URL jarUrl = JythonServer.class.getProtectionDomain().getCodeSource().getLocation();
    String jarPath = jarUrl.getPath();
    if (jarUrl.getProtocol().equals("file")) {
        // If URL is of type file, assume that we are in dev env and set path to python dir.
        // else use the jar file as is
        jarPath = jarPath + "../../src/main/python/";
    }

    p.exec("import sys");
    p.exec("sys.path.append('" + jarPath + "')");
    p.exec("from debugserver import run_server");
    if (this.host == null) {
    	p.exec("run_server(port=" + this.port + ", locals=locals())");
    } else {
    	p.exec("run_server(port=" + this.port + ", host='" + this.host + "', locals=locals())");
    }
}
 
開發者ID:hksoni,項目名稱:SDN-Multicast,代碼行數:29,代碼來源:JythonServer.java

示例2: run

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
/**
 * The main thread for this class invoked by Thread.run()
 *
 * @see java.lang.Thread#run()
 */
public void run() {
    PythonInterpreter p = new PythonInterpreter();
    for (String name : this.locals.keySet()) {
        p.set(name, this.locals.get(name));
    }

    URL jarUrl = JythonServer.class.getProtectionDomain().getCodeSource().getLocation();
    String jarPath = jarUrl.getPath();
    if (jarUrl.getProtocol().equals("file")) {
        // If URL is of type file, assume that we are in dev env and set path to python dir.
        // else use the jar file as is
        jarPath = jarPath + "../../src/main/python/";
    }

    p.exec("import sys");
    p.exec("sys.path.append('" + jarPath + "')");
    p.exec("from debugserver import run_server");
    p.exec("run_server(" + this.port + ", '0.0.0.0', locals())");
}
 
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:25,代碼來源:JythonServer.java

示例3: apply

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
@Override
public ConstructionList apply( ConstructionList parameters, AttributeMap attrs, ConstructionChanges effects )
throws Command.Failure
{
    ConstructionList result = new ConstructionList();
    if ( parameters .size() != 1 )
        throw new Failure( "start parameter must be a single connector" );
    Construction c = parameters .get( 0 );
    if ( ! ( c instanceof Point ) )
        throw new Failure( "start parameter must be a connector" );
    Point pt1 = (Point) c;
    String script = (String) attrs .get( SCRIPT_ATTR );
    final Symmetry symm = (Symmetry) attrs .get( CommandTransform.SYMMETRY_GROUP_ATTR_NAME );

    ZomicVirtualMachine builder = new ZomicVirtualMachine( pt1, effects, symm );

    PythonInterpreter interp = new PythonInterpreter();
    interp .set( "zomicVM", builder );
    interp .exec( script );

    result .addConstruction( builder .getLastPoint() );
    return result;
}
 
開發者ID:vZome,項目名稱:vzome-core,代碼行數:24,代碼來源:CommandExecutePythonScript.java

示例4: main

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public static void main(String... args) {
    PythonInterpreter pythonInterpreter = new PythonInterpreter();

    int count = 0;
    for(String arg : args) {
        try {
            count++;
            pythonInterpreter.set("number" + count, new Integer(arg));
        }
        catch (NumberFormatException e) {
            System.err.println(arg + " is not a number!");
            count--;
        }
    }
    pythonInterpreter.set("sum", 0);
    for(int i = 1; i <= count; i++) {
        pythonInterpreter.exec(String.format("sum += %s", "number"+i));
    }
    PyObject sum = pythonInterpreter.get("sum");
    System.out.println("The result is: " + sum.toString());
}
 
開發者ID:ghajba,項目名稱:JaPy,代碼行數:22,代碼來源:PythonCalling.java

示例5: process

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
private Tokens process(Object lexer, String code) {
    PythonInterpreter interpreter = gateway.getInterpreter();

    Tokens tokens = new Tokens();

    interpreter.set("code", code);
    interpreter.set("lexer", lexer);
    interpreter.set("out", new RFormatter(tokens));

    // Simple use Pygments as you would in Python
    interpreter.exec(""
            + "from pygments import highlight\n"
            + "from pygments.formatter import Formatter\n"
            + "\n"
            + "class ForwardFormatter(Formatter):\n"
            + "    def format(self, tokensource, outfile):\n"
            + "        for ttype, value in tokensource:\n"
            + "            out.write(ttype, value)\n"
            + "\n"
            + "result = highlight(code, lexer, ForwardFormatter())");

    return tokens;
}
 
開發者ID:Arnauld,項目名稱:gutenberg,代碼行數:24,代碼來源:Pygments.java

示例6: evalLookupLexer

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
private Object evalLookupLexer(PyGateway gateway, String alias, Object notFoundFallback) {
    Object result;
    try {
        PythonInterpreter interpreter = gateway.getInterpreter();
        interpreter.set("alias", alias);
        interpreter.exec(""
                + "from pygments.lexers import get_lexer_by_name\n"
                + "result = get_lexer_by_name(alias)");

        result = interpreter.get("result");
    } catch (PyException e) {
        log.warn("Unable to find Pygments lexer for alias '{}'", alias);
        result = notFoundFallback;
    }
    return result;
}
 
開發者ID:Arnauld,項目名稱:gutenberg,代碼行數:17,代碼來源:Lexers.java

示例7: runCxxTestGen

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
private void runCxxTestGen( String testTarget, List<String> arguments ) throws MojoExecutionException
{
    final String cxxTestGenArgVar = "cxxTestGenArgs";
    
    String cxxTestGenPath = cxxTest.getCxxTestHome().getAbsolutePath();
    PyList cxxTestGenArgs = new PyList( arguments );
    cxxTestGenArgs.add( 0, cxxTestGenPath );
    
    getLog().info( "Executing test runner generation for target " + testTarget + "." );
    getLog().debug( "Executing Python script " + cxxTestGenPath + " with arguments=" + cxxTestGenArgs );

    PythonInterpreter pythonInterpreter = new PythonInterpreter();
    pythonInterpreter.exec( "import cxxtest" );
    resetCxxTestSuites( pythonInterpreter );
    
    pythonInterpreter.set( cxxTestGenArgVar, cxxTestGenArgs );
    pythonInterpreter.exec( "cxxtest.main(" + cxxTestGenArgVar + ")" );  
    pythonInterpreter.cleanup();
    
    getLog().info( "Test runner generation for target " + testTarget + " succeeded." );
}
 
開發者ID:andi12,項目名稱:msbuild-maven-plugin,代碼行數:22,代碼來源:CxxTestGenMojo.java

示例8: PythonExecutor

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public PythonExecutor(Object extension) throws PythonWrapperError {
    String scriptPath = getScriptPath(extension);
    pinterp = new PythonInterpreter();
    pinterp.exec("import sys");
    String modulePath = new File(scriptPath).getParent();
    modulePath = modulePath.replace("\\", "\\\\");
    modulePath = modulePath.replace("'", "\\'");
    String cmdPath = "sys.path.append('" + modulePath + "')";
    pinterp.exec(cmdPath);
    pinterp.execfile(scriptPath);
    pinterp.set("extension", extension);
    callId = 0;
    this.extension = extension;
    if (hasFunction("init_plugin", 0)) {
        pinterp.exec("init_plugin()");
    }
}
 
開發者ID:conyx,項目名稱:jenkins.py,代碼行數:18,代碼來源:PythonExecutor.java

示例9: markdownToHtml

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public static String markdownToHtml(MdTextController index, String chaine) {
    PythonInterpreter console = index.getPyconsole();
    console.set("text", chaine);
    console.exec("render = mk_instance.convert(text)");
    PyString render = console.get("render", PyString.class);
    return render.toString();
}
 
開發者ID:firm1,項目名稱:zest-writer,代碼行數:8,代碼來源:MenuController.java

示例10: testPythonWithObject

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
@Test
public void testPythonWithObject() {
    PythonInterpreter python = PythonFactory.newInterpreter();
    TestObject foo = new TestObject();
    foo.value = 100;

    python.set("foo", foo);
    python.exec("foo.value *= 2");
    TestObject fooAgain = python.get("foo", TestObject.class);

    assertEquals(200, fooAgain.value);
    assertEquals(200, foo.value);
}
 
開發者ID:tanium,項目名稱:pyjenkins,代碼行數:14,代碼來源:PythonFactoryTest.java

示例11: 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

示例12: executeCommand

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public void executeCommand(String cmd){
	PythonInterpreter interpreter = new PythonInterpreter();
	Vector<AndroidDriver> drivers = new Vector();
	drivers.add(this);
	interpreter.set("device", drivers);
	interpreter.exec(cmd); 
}
 
開發者ID:hoozheng,項目名稱:AndroidRobot,代碼行數:8,代碼來源:AndroidDriver.java

示例13: perform

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
@Override
  public void perform() throws Failure
  {
  	// The delegate interface is carefully designed to keep the API public,
  	//  but keep the knowledge of ModelRoot, Selection, and ChangeConstructions, etc. here.
  	
  	Command.Delegate delegate = this .createDelegate();
  	
  	Properties props = new Properties();
  	props .setProperty( "python.path", "/Library/Python/2.7/site-packages" );
  	
  	// TODO this could be done once, when the python console is opened
      InteractiveConsole.initialize( System.getProperties(), props, new String[0] );
      
      PythonInterpreter interp = new PythonInterpreter();
      interp .setOut( System.out );
      interp .setErr( System.err );
      interp .set( "javaCommand", new Command( delegate ) );
      try {
	interp .exec( "import vzome" );
	interp .exec( "command = vzome.Command( cmd=javaCommand )" );
	interp .exec( this .programText );
} catch ( PyException e ) {
	e.printStackTrace();
	throw new Failure( e.toString() );
}
      redo();
  }
 
開發者ID:vZome,項目名稱:vzome-core,代碼行數:29,代碼來源:RunPythonScript.java

示例14: initPythonInterpreter

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
/**
 * ��ʼ��Python���沢���PythonInterpreter
 * 
 * @param queryData ��ѯ����
 * @param sql SQL���
 * @param values ѡ��ֵ
 * @param params ����
 * @param page ��ǰҳ
 * @param pageSize ��ҳ��С
 * @return PythonInterpreter ʵ��
 */
public PythonInterpreter initPythonInterpreter(SimpleAspectWrapper simpleWrapper)
{
    PythonInterpreter pyInter = JythonFactory.getInstance().getInterpreter();
    if (simpleWrapper instanceof QueryAspectWrapper)
    {
        pyInter.set(JY_ASPECT_DATA, (QueryAspectWrapper)simpleWrapper);
    }
    else
    {
        pyInter.set(JY_ASPECT_DATA, simpleWrapper);
    }
    return pyInter;
}
 
開發者ID:liulhdarks,項目名稱:darks-orm,代碼行數:25,代碼來源:PythonParser.java

示例15: execute

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
public void execute(Writer writer, SnipMacroParameter params)
    throws IllegalArgumentException, IOException {

  PythonInterpreter interp =
      new PythonInterpreter();

  interp.setOut(writer);
  interp.set("snip", params.getSnipRenderContext().getSnip());
  interp.exec(params.getContent());
}
 
開發者ID:thinkberg,項目名稱:snipsnap,代碼行數:11,代碼來源:ScriptMacro.java


注:本文中的org.python.util.PythonInterpreter.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。