Jython: preload PythonInterpreter with values for use in scripts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harald Kirsch

    Jython: preload PythonInterpreter with values for use in scripts

    How can I set variables in PythonInterpret er such that
    scripts then run via import can have access to it.

    My idea was to go along the lines of:

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

    Within mystuff.py I wanted to do things like

    m = sys.modules['__main__']
    m.javaCaller.se tThoseNiftyFeat uresOfTheCallin gJavaObject("he llo")

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

    Is there any way to get hold of locals() of PythonInterpret er 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.
Working...