|
From: Jim A. <ji...@tr...> - 2001-04-11 00:10:17
|
Jayson Baird wrote:
>
> hi all,
>
> When trying to run a script inside of a java looping body, like so:
> interpreter.set("x", new PyInteger(42));
> while(infile.ready()) {
> interpreter.exec(infile.readLine());
> }
>
> I get the following error with the following python code:
> Exception in thread "main" Traceback (innermost last):
> (no code object) at line 0
> File "<string>", line 2
> SyntaxError: invalid syntax
>
> the file I'm reading from is as follows:
> if x == 42:
> x = x + 1;
>
> running anything but an if statement works just fine.. all my python
> books say that is the right syntax... any ideas?
>
> Jayson Baird
> js...@ci...
It looks like the 'if' statement (and 'for') can't be split across
'exec' statments.
Neither this:
python.exec("if 1:");
python.exec(" print 'true'");
nor this:
python.exec("for x in range(1,2):");
python.exec(" print x");
work for me. Of course this works:
python.exec("for x in range(1,2): print x");
or this (multiple lines in a SINGLE 'exec':
String s = "if 1: \n print 'true'";
python.exec(s);
--
__o
Jim Adrig _ \<,_
ji...@tr... ' `/ ' `
___________ `-' `-'
.
|