本文整理汇总了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())");
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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." );
}
示例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()");
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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());
}