Hi Ben,

eval is meant for expressions. What you want to use is exec

Object objResult = objInterp.exec(strScript);


On 05-Dec-06, at 2:48 AM, Neil Benn wrote:

Hello,

††††††††††† I am trying to evaluate a script which runs as follows (using both BSF and JYthonInterp does the same thing):

---

String strScript = "def test():\n";

strScript += "\treturn 1\n";

strScript += "test()";

Object objResult = objInterp.eval(strScript);

---

However I get the following traceback (this is when run from JythonInterp), Iíve snipped the bottom bit off because it is in the unit test code

††††††††††† Traceback (innermost last):

(no code object) at line 0

SyntaxError: ('invalid syntax', ('<string>', 1, 1, 'def test():'))

††††††††††† at org.python.core.parser.fixParseError(parser.java)

††††††††††† at org.python.core.parser.parse(parser.java)

††††††††††† at org.python.core.Py.compile_flags(Py.java)

††††††††††† at org.python.core.Py.compile_flags(Py.java)

††††††††††† at org.python.core.__builtin__.eval(__builtin__.java)

††††††††††† at org.python.core.__builtin__.eval(__builtin__.java)††††††††††††††††††††††††††††††††††††

††††††††††† at org.python.util.PythonInterpreter.eval(PythonInterpreter.java)

††††††††††† at uk.co.ziath.datapaq.server.scripting.JythonScriptProcessor.evaluateScript(JythonScriptProcessor.java:76)

††††††††††† at uk.co.ziath.datapaq.server.scripting.test.JythonScriptProcessorTest.testMethodJythonScript(JythonScriptProcessorTest.java:75)

<snip>

---

††††††††††† When I attempt to run a simple script such as 3* 4 and evaluate it, I get back 12 as I would expect.However it seems that any multi-line script fails on me.Is it true that I cannot use a multi-line script in an evaluate statement (I know I can do it in an execute statement)?

††††††††††† Thanks for your help.

Cheers,

Neil

---

Neil Benn

CEO Ziath Ltd

http://www.ziath.com

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users