我已将控制台输出重定向到以下代码的txt文件,但是有没有办法将结果分配给本地变量?例如如果输出是'Hello World',我想把它分配给一个String变量。Jython中的PythonInterpreter - 存储结果
我在看PythonInterpreter API,我有些困惑,因为它对我来说是新的 (http://www.jython.org/javadoc/org/python/util/PythonInterpreter.html)。
我一直在玩setIn和setOut方法,但没有得到它的工作。
非常感谢您的建议。
public static void main(String[] args) {
// Create an instance of the PythonInterpreter
PythonInterpreter interp = new PythonInterpreter();
// The exec() method executes strings of code
interp.exec("import sys");
interp.exec("print sys");
interp.execfile("C:/Users/A/workspace/LeaerningPyDev/helloWorld.py");
}
嗨stewori,感谢您的意见。我会试试这个。 – user3742439