Jython, getting instance name from the interpreter

Ype Kingma ykingma at accessforall.nl
Sun May 4 14:03:04 EDT 2003


tommys wrote:

> Does anyone know to get the instance names from the interpreter?
> I want the getMyName method to return "instance" in this case, or a
> list of names if many...
>
> Thanks for any help!!
>
> Tommy
>
> public class InterPreter() {
> private static PythonInterpreter interp = new PythonInterpreter();
> private static String myscript = "instance = MyClass()";
> public InterPreter() {interp.exec(myscript);}
>
>
> public static String getInstanceName(Myclass mycl) {
>
> //hmm, how to do this?
>
> }
> }
> public class MyClass() {
>
>
> public String getMyName() {
> return InterPreter.getInstanceName(this);
> }


Python does not provide a one to one relationship between
objects and names: a python object may be referred to by
any number of names.

In your case you could provide a one to one relationship
in your java class:

public class InterPreter() {
private static PythonInterpreter interp = new PythonInterpreter();
private static String instanceName = "instance";
private static String myscript = instanceName + " = MyClass()";

public InterPreter() {interp.exec(myscript);}

public static String getInstanceName(Myclass mycl) {return instanceName;}
}



Have fun,
Ype

--
email at xs4all.nl




More information about the Python-list mailing list