keep Java object alive between two script

Wilson Chew wchew at qualcomm.com
Tue Jul 20 21:04:20 CEST 2004


Hi,

This is more of a Jython question, I guess.
Say I have a Java program MyJavaClass which will be called from two Jython
scripts: script_1.py and script_2.py:
----------------------------------------------
#script_1.py
from MyJavaClass import *

myObj = MyJavaClass()
myObj.startJavaFunc()    #startJavaFunc() is a method in MyJavaClass()

==============================


Then I have a Manager class that will invoke these scripts, as shown below:
------------------------------------------------
package TestSuiteManager;
import org.python.util.PythonInterpreter;
import org.python.core.*;

public class TestSuiteManager {

    public static void main(String[] args)
    {
        PythonInterpreter interp = new PythonInterpreter();
        interp.execfile("script_1.py");
        // will I be able to keep "myObj" alive after the execution of
script_1.py ?
       //  will I be able to somehow get the object "myObj" that was created
in script_1.py and use it?
        interp.execfile("script_2.py");
    }
}
================================
My questions are written in the program above as comments.

Thanks everyone in advance.


Wilson Chew
Summer Intern,
Qualcomm. Inc.





More information about the Python-list mailing list