【发布时间】:2015-02-02 02:31:29
【问题描述】:
import org.python.util.PythonInterpreter;
public class JythonTest {
public static void main(String[] args) {
PythonInterpreter interp = new PythonInterpreter();
interp.exec("if 2 > 1:");
interp.exec(" print('in if statement!'");
}
}
我需要能够从 Java 程序执行 Python 代码,因此决定尝试 Jython,但我不熟悉它。我尝试执行上面的代码,但得到了错误:“线程中的异常“main”SyntaxError:(“mismatched input '' Expecting INDENT”, ('', 1, 9, 'if 2 > 1:\n')) ”。任何想法这意味着什么或我如何使用 PythonInterpreter 执行 if 语句?
【问题讨论】:
-
你在使用 Eclipse 吗?
-
是的,我正在使用 Eclipse!
-
我有一个建议,请稍等,我会发布另一个答案。