From: Robert W. B. <rb...@di...> - 2001-08-21 17:47:56
|
The example I sent has at least 2 errors that need corrected. error 1- The "embed.test()" line should read "embed.useInterp()". error 2- the initialize arguments are wrong corrections noted below. sorry about that. On Tue, 21 Aug 2001, Robert W. Bill wrote: > > import java.util.Properties; > import org.python.util.PythonInterpreter; > > public class embeddingExample { > > protected PythonInterpreter interp; > > public static void main(String[] args) { > embeddingExample embed = new Embedding(); > embed.startInterp(); > // embed.test(); <-- ERROR embed.useInterp(); // <-- CORRECTION > } > > protected void startInterp() { > Properties props = new Properties(); > > if (System.getProperty("python.home") == null) > props.put("python.home", "/usr/local/jython"); //CORRECTED initialize method here PythonInterpreter.initialize(System.getProperties(), props, new String[0]); > interp = new PythonInterpreter(); > } > > public void useInterp() { > // define and call a Jython function > interp.exec("def test(message):\n" + > " print message"); > interp.exec("test('Hello world')"); > > // you can import Python modules as use them just as easily > interp.exec("import glob\n" + > "print glob.glob('*')"); > > } > } |