本文整理了Java中org.python.util.PythonInterpreter.execfile()
方法的一些代码示例,展示了PythonInterpreter.execfile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PythonInterpreter.execfile()
方法的具体详情如下:
包路径:org.python.util.PythonInterpreter
类名称:PythonInterpreter
方法名:execfile
[英]Executes a file of Python source in the local namespace.
[中]在本地命名空间中执行Python源文件。
代码示例来源:origin: org.freemarker/freemarker
public void execute(File file, Map vars) throws BuildException {
PythonInterpreter pi = createInterpreter(vars);
try {
pi.execfile(file.getCanonicalPath());
} catch (IOException e) {
throw new BuildException(e);
}
}
代码示例来源:origin: spring-projects/spring-security
public boolean before(Authentication authentication, MethodInvocation mi,
PreInvocationAttribute preAttr) {
PythonInterpreterPreInvocationAttribute pythonAttr = (PythonInterpreterPreInvocationAttribute) preAttr;
String script = pythonAttr.getScript();
PythonInterpreter python = new PythonInterpreter();
python.set("authentication", authentication);
python.set("args", createArgumentMap(mi));
python.set("method", mi.getMethod().getName());
Resource scriptResource = new PathMatchingResourcePatternResolver()
.getResource(script);
try {
python.execfile(scriptResource.getInputStream());
}
catch (IOException e) {
throw new IllegalArgumentException("Couldn't run python script, " + script, e);
}
PyObject allowed = python.get("allow");
if (allowed == null) {
throw new IllegalStateException("Python script did not set the permit flag");
}
return (Boolean) Py.tojava(allowed, Boolean.class);
}
代码示例来源:origin: nodebox/nodebox
public ImmutableMap<String, Function> call() throws Exception {
// This creates a dependency between function and the client.
// However, we need to know the load paths before we can do anything, so this is necessary.
PythonUtils.initializePython();
Py.getSystemState().path.append(new PyString(file.getParentFile().getCanonicalPath()));
PythonInterpreter interpreter = new PythonInterpreter();
try {
interpreter.execfile(file.getCanonicalPath());
} catch (IOException e) {
throw new LoadException(file, e);
} catch (PyException e) {
throw new LoadException(file, e);
}
PyStringMap map = (PyStringMap) interpreter.getLocals();
ImmutableMap.Builder<String, Function> builder = ImmutableMap.builder();
for (Object key : map.keys()) {
Object o = map.get(Py.java2py(key));
if (o instanceof PyFunction) {
String name = (String) key;
Function f = new PythonFunction(name, (PyFunction) o);
builder.put(name, f);
}
}
return builder.build();
}
});
代码示例来源:origin: org.python/jython
public void testConstructorKWArgs() {
interp.execfile("tests/python/constructorkwargs_test.py");
}
}
代码示例来源:origin: org.python/jython
public void testReadonly() {
interp.execfile("tests/python/identity_test.py");
}
}
代码示例来源:origin: org.python/jython
public void testShadowing() {
interp.execfile("tests/python/prop_test.py");
}
代码示例来源:origin: org.python/jython
public void execfile(java.io.InputStream s) {
execfile(s, "<iostream>");
}
代码示例来源:origin: stackoverflow.com
import org.python.util.PythonInterpreter;
public class JythonTest {
public static void main(String[] args) {
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.execfile("a.py");
pythonInterpreter.execfile("b.py");
}
}
代码示例来源:origin: stackoverflow.com
Properties properties = System.getProperties();
properties.put("python.path", PATH_TO_PARENT_DIRECTORY_OF_AS1_PY);
PythonInterpreter.initialize(System.getProperties(), properties, new String[0]);
PythonInterpreter interp = new PythonInterpreter();
interp.execfile("calen.py");
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Load a Jython deployed script
*
* @param stream InputStream with Jython code to load
*/
private static void loadJythonScript(InputStream stream) {
JythonUtils.getInterpreter().execfile(stream);
}
代码示例来源:origin: org.freemarker/freemarker-gae
public void execute(File file, Map vars) throws BuildException {
PythonInterpreter pi = createInterpreter(vars);
try {
pi.execfile(file.getCanonicalPath());
} catch (IOException e) {
throw new BuildException(e);
}
}
代码示例来源:origin: ch.epfl.bbp.nlp/bluima_jython
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
try {
interp.set("jcas", jcas); // make jcas available in script
interp.execfile(scriptFileIs);
} catch (Exception e) {
throw new AnalysisEngineProcessException(
AnalysisEngineProcessException.ANNOTATOR_EXCEPTION,
new Object[] {}, e);
}
}
}
代码示例来源:origin: org.freemarker/com.springsource.freemarker
public void execute(File file, Map vars) throws BuildException {
PythonInterpreter pi = createInterpreter(vars);
try {
pi.execfile(file.getCanonicalPath());
} catch (IOException e) {
throw new BuildException(e);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker
public void execute(File file, Map vars) throws BuildException {
PythonInterpreter pi = createInterpreter(vars);
try {
pi.execfile(file.getCanonicalPath());
} catch (IOException e) {
throw new BuildException(e);
}
}
代码示例来源:origin: stackoverflow.com
import org.python.util.PythonInterpreter;
public class FirstJavaScript {
public static void main(String args[]) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("/home/XXX/XXX/test.py");
}
}
代码示例来源:origin: stackoverflow.com
import org.python.util.PythonInterpreter;
public class JythonTest {
public static void main(String[] args) {
PythonInterpreter interp = new PythonInterpreter();
interp.execfile("src/script.py");
}
}
代码示例来源:origin: stackoverflow.com
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
public class method {
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("/pathtoyourmodule/somme_x_y.py");
PyObject str = interpreter.eval("repr(somme(4,5))");
System.out.println(str.toString());
}
代码示例来源:origin: org.picocontainer.script/picocontainer-script-jython
protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) {
try {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.set("parent", parentContainer);
interpreter.set("assemblyScope", assemblyScope);
interpreter.execfile(getScriptInputStream(), "picocontainer.py");
return (PicoContainer) interpreter.get("pico", PicoContainer.class);
} catch (IOException e) {
throw new ScriptedPicoContainerMarkupException(e);
}
}
}
代码示例来源:origin: org.twdata.enchanter/enchanter-python
public static void main(String[] args) throws IOException {
ScriptRecorder rec = new PythonScriptRecorder();
args = rec.processForLearningMode(args);
String filePath = args[0];
PythonInterpreter interp = new PythonInterpreter();
StreamConnection conn = new DefaultStreamConnection();
// deprecated
interp.set("ssh", conn);
interp.set("conn", conn);
interp.set("args", args);
interp.execfile(filePath);
}
代码示例来源:origin: stackoverflow.com
PythonInterpreter py = new PythonInterpreter();
String dataFolder,prepFolder;
py.execfile("filename.py");
py.set("df", dataFolder);
py.set("pf", prepFolder);
py.exec("prep = Preprocess(df, pf)");
//if the preprocess method does not return anything, you can do:
py.exec("prep.preprocess()");
//To get the return value in java, you can do:
SomeJavaClass retvalue = py.eval("prep.preprocess()").__tojava__(SomeJavaClass.class);
//To get and store the return type in the python local namespace:
py.exec("retValue = prep.preprocess()");
内容来源于网络,如有侵权,请联系作者删除!