From: Justin W. <Jus...@mo...> - 2002-01-10 17:41:24
|
Hi, I am using jython embedded in java, specifically the PythonInterpreter class. I have a java object containing a series of member variables. I want to pass it into the interpreter and generate an array based on those member variables and a user-defined jython script. I then want to take the resulting array and drop out of the interpreter / back into java. I can pass the object into the interpreter and generate the result array no problem. The difficulty seems to be getting out of the interpreter. In the docs, the only way out I can see is via a PyObject object (from PythonInterpreter.get(String _name)) - I can have my result array either as a list or as a jarray, export it using this method and then re-cast to a PyArray. But how then do I convert to a java object or array ? I thought the following looked promising, PythonInterpreter interp=new PythonInterpreter(); interp.exec("import jarray"); interp.exec("x=jarray.array([1,2,3],'i')"); PyArray x=(PyArray)interp.get("x"); Class c=PyArray.char2class('i'); Object o=x.__tojava__(c); System.out.println(o.toString()); but it generates the result 'Error' which doesn't look promising (why is no exception thrown?) Thanks! |