Jython: syntax check available?

49 Views Asked by At

I am using Jython for a simple Python script task inside a Java app.

Properties ps = new Properties();
ps.put ("python.console.encoding", "UTF-8");
ps.put ("python.import.site", "false");
PythonInterpreter.initialize (System.getProperties (), ps, new String [0]);
this.pi = new PythonInterpreter ();

String pycode = "print \"abc\"";
pi.exec (pycode);

This works, but now I need to think of a way to check the code before it is executed.

I tried pi.compile:

PyCode pc = pi.compile (pycode);
pi.exec (pc);

But I do not see any effect with that regarding my problem.

Method compile produces a result even if exec fails afterwards (e.g. wrong syntax).

0

There are 0 best solutions below