Message5816

Author frbo
Recipients frbo
Date 2010-06-16.15:20:41
SpamBayes Score 5.125294e-05
Marked as misclassified No
Message-id <1276701642.46.0.790498042258.issue1621@psf.upfronthosting.co.za>
In-reply-to
Content
public class JythonTest
{
  public static void main(String anArguments[]) throws Exception
  {
    jythonDirect();
    jythonJSR223();
  }

  private static void jythonDirect()
  {
    PythonInterpreter myInterpreter = new PythonInterpreter();
    myInterpreter.exec(
      "from java.lang import String\n" +
      "myString = String('Test')\n" +
      "myResult = myString.substring(1,2)");

    System.out.println("Direct Jython result: " +
      myInterpreter.get("myResult"));
  }

  private static void jythonJSR223()
      throws ScriptException
  {
    ScriptEngine myEngine = new ScriptEngineManager(). 
      getEngineByName("jython");
    if (myEngine == null)
    {
      throw new RuntimeException("Script engine not found!");
    }

    myEngine.eval(
      "from java.lang import String\n" +
      "myString = String('Test')\n" +
      "myResult = myString.substring(1,2)");

    System.out.println("JSR223 result: " + myEngine.get("myResult"));
  }
}
History
Date User Action Args
2010-06-16 15:20:42frbosetmessageid: <1276701642.46.0.790498042258.issue1621@psf.upfronthosting.co.za>
2010-06-16 15:20:42frbosetrecipients: + frbo
2010-06-16 15:20:42frbolinkissue1621 messages
2010-06-16 15:20:41frbocreate