|
From: <bc...@wo...> - 2001-02-12 09:55:51
|
[Jayson S Baird]
>Here is a crude python program for example purposes:
> for each i in <some list>
> print i
>
> with that, will a straight PythonInterpreter.exec(line) by a good enough
>shell interpreter for doing on the fly python interpreting? Or is there
>more higher level stuff to be done?
The PythonInterpreter.exec(s) takes an entire script, not individual
lines. The little example script can be embedded like this:
import org.python.core.*;
import org.python.util.*;
public class si2 {
public static void main(String[] args) {
PythonInterpreter interp = new PythonInterpreter();
interp.exec("for i in (1,2,3):\n print i");
}
}
Note that the script contains newlines and indentation *exactly* as it
would, if it came from a file:
for i in (1,2,3):
print i
regards,
finn
|