[Jython] Pass variable or class reference to PythonInterpreter?

Robert Oschler Oschler at earthlink.net
Thu Nov 7 09:15:25 EST 2002


"Alex Martelli" <aleax at aleax.it> wrote in message
news:qVpy9.1040$XO.51258 at news2.tin.it...
> Robert Oschler wrote:
>
>
> Sure, Jython's PythonInterpreter class gives you methods you
> can use for this purpose.  interp.set("theString", theString)
> for example would add an attribute named "theString" to the
> inteprreter's local namespace, with its value set to the Java
> value theString.  *CHANGING* it is obviously out of the question
> (strings are immutable in Java *AND* in Python), but THAT
> is clearly a completely different issue.
>

Alex,

Re: String == immutable.  Sure, but other types and user classes are OK
right?  At least that's what the tests I ran indicated.  I did discover that
a the class of a instance variable passed to the python interpreter via the
set() method, must be public if it's going to be accessed by the Python
Interpreter, otherwise you get a Java illegal access exception when Jython
tries to reflect the class.  I would have thought private inner classes,
'inner' to the class whose method created the PythonInterpreter insntance,
would have been OK but they're not.

thx






More information about the Python-list mailing list