Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Jython: preload PythonInterpreter with values for use in scripts (http://www.velocityreviews.com/forums/t319859-jython-preload-pythoninterpreter-with-values-for-use-in-scripts.html)

Harald Kirsch 07-18-2003 04:55 PM

Jython: preload PythonInterpreter with values for use in scripts
 
How can I set variables in PythonInterpreter such that
scripts then run via import can have access to it.

My idea was to go along the lines of:

PythonInterpreter ip = new PythonInterpreter();
// make the object about to use the interpreter
// available to that interpreter
ip.set("javaCaller", this);
ip.exec("import mystuff");

Within mystuff.py I wanted to do things like

m = sys.modules['__main__']
m.javaCaller.setThoseNiftyFeaturesOfTheCallingJava Object("hello")

Alas, sys.modules does not contain '__main__'.

Is there any way to get hold of locals() of PythonInterpreter ip within
a module imported as shown above?

I would expect that execfile allows the above communication,
but then I have to do all the searching for the module myself.
Therefore a solution where the module is simply imported as above
is preferred.

Thanks,
Harald.


All times are GMT. The time now is 02:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57