Reinitializing the python interpreter form Java

Ype Kingma ykingma at accessforall.nl
Wed May 23 17:02:56 EDT 2001


"Andre M. Descombes" wrote:
> 
> Hi,
> 
> I am using Jython as a script language from within Java, I compile a Python
> program using the PythonInterpreter.exec method (so it runs faster), and

It won't run faster. I will probably load faster.

> then use PythonInterpreter.get to get an address to a PyObject and then use
> __call__ to call the code.
> 
> The problem is I would like to execute some functions several times, and I
> would like to be able to save the state of the global variables, so I can
> later restore it (on a different day for example).
> 
> I tried using getLocals and setLocals with no success.

Did you make a copy of the dictionary returned by getLocals()?

    savedLocals = getLocals().copy()

Each time you run your program you will have to pass it a fresh
copy of this copy, too:

    interpr.setLocals(savedLocals.copy())

The fresh copy will give the restore effect.

Have fun,
Ype

-- 
email at xs4all.nl



More information about the Python-list mailing list