00001 package edu.tum.cs.tools; 00002 00003 import java.util.Formatter; 00004 00005 import org.python.core.PyObject; 00006 import org.python.core.PyObject.ConversionException; 00007 import org.python.util.PythonInterpreter; 00008 00009 public class JythonInterpreter extends PythonInterpreter { 00010 public JythonInterpreter() { 00011 super(); 00012 } 00013 00014 public void exec(String command, Object ... args) { 00015 command = new Formatter().format(command, args).toString(); 00016 this.exec(command); 00017 } 00018 00019 public PyObject eval(String command, Object ... args) { 00020 command = new Formatter().format(command, args).toString(); 00021 return this.eval(command); 00022 } 00023 00024 public int evalInt(String command, Object ... args) throws ConversionException { 00025 return eval(command, args).asInt(0); 00026 } 00027 00028 public boolean evalBoolean(String command, Object ... args) throws ConversionException { 00029 return evalInt(command, args) == 1; 00030 } 00031 00032 public String evalString(String command, Object ... args) throws ConversionException { 00033 return eval(command, args).toString(); 00034 } 00035 00036 public double evalDouble(String command, Object ... args) throws NumberFormatException, ConversionException { 00037 return Double.parseDouble(evalString(command, args)); 00038 } 00039 }