|
From: Jim A. <ji...@tr...> - 2001-03-22 19:01:45
|
Ron...@Ne... wrote:
>
> I have a bunch of properties that I get from the system using Java code,
> since that is what handles properties. The data I get back is of type
> java.lang.String. These things are used all over the place.
>
> Which makes more sense: write all the code in Java and just drive it
> with Jython, or convert the String data to Python strings? In the latter
> case, how do I do the conversion?
>
Of course it depends on your purpose, but I would lean toward putting
the info into Jython.
Here's a cut/paste of some of my code:
import org.python.util.PythonInterpreter;
import org.python.core.*;
...
PythonInterpreter python;
python = new PythonInterpreter();
python.set("debugLevel", new Integer(debugLevel)
); // must pass Object not 'int'
python.set("amount", new PyFloat( Double.parseDouble( amountString )
) ); // so Jython can do math directly
ArrayList errorList = new ArrayList();
python.set("errorList", errorList);
Note that in the last example, the pointer to the ArrayList is sent to
Jython: in the Jython code it calls other Java code using the same
pointer ('errorList'), and the Java code actually 'add's to the
errorList; i.e. the pointer is just 'passed through' Jython.
This all works great and fast since when it actually runs, Jython code
is just Java Bytecodes !
Your other option is just to call the Java classes to get the properties
from Jython directly. See Bruce Eckel's Jython info below for more info.
--
__o
Jim Adrig _ \<,_
ji...@tr... ' `/ ' `
___________ `-' `-'
Java/Jython intergration: Chapter 9 at:
http://www.bruceeckel.com/TIPatterns/index.html
|