However, if I pass each line separately, then it throws an exception when reading the while statement since it expects some code with indentation after the while statement. The error message is
("mismatched input '<EOF>' expecting INDENT", ('<string>', 3, 11, 'while a<10:\n'))
That '3' is a line number — parse it out. (But Nicholas's idea is better — grab the exception and ask it directly).
I have another question as well.
The PythonInterpreter object has all the local variables that have been assigned a value during execution. Is there a way I can get a list of all the local variables and their values? Currently, I am parsing the code myself to figure out all the variables that might have been assigned a value and then am asking the PythonInterpreter (Object value = interp.get(variableName)) to fetch the value corresponding to that variable.
What we do: when you make a PythonInterpreter pass in your own subclass of PyStringMap to act as the globals space for that interpreter. Track set's and get's by overriding __finditem__ and __setitem__.