From: Samuele P. <pe...@in...> - 2001-07-12 13:23:22
|
Hi. [Jim Aldrig] > Mark Ackerman wrote: > > > > I've got an embedded Jython interpretor as my glue in a java program. > > I'm trying to do an exec or eval (both actually), sending an entire program > > in as a string. It's not working. I can use the exact same program as > > a file using execfile, and then it's fine. > > > > Any suggestions? I'm using \n as my line delimiter, if that helps. > > It doesn't work like that: 'exec' only takes one 'unit' of code; Just to avoid confusion, that's false. interp.exec takes the same arg "as" the exec statement: http://www.python.org/doc/current/ref/exec.html e.g. the following example works for me: import org.python.util.* ; public class interp { public static void main(String[] args) { PythonInterpreter interp = new PythonInterpreter(); String x = "a,b=1,1\nif a:\n print 3\nif b:\n print 5"; interp.exec(x); } } Clearly one should pay attention to indentation. Passing chunks of code, e.g. incomplete compound statements does not work, OTOH. regards, Samuele Pedroni. |