Jython: preload PythonInterpreter with values for use in scripts

Discussion in 'Python' started by Harald Kirsch, Jul 18, 2003.

  1. 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.setThoseNiftyFeaturesOfTheCallingJavaObject("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.
    Harald Kirsch, Jul 18, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David McNab
    Replies:
    0
    Views:
    484
    David McNab
    Apr 9, 2004
  2. scott
    Replies:
    1
    Views:
    382
    Diez B. Roggisch
    Apr 21, 2005
  3. HK
    Replies:
    0
    Views:
    420
  4. Divya Prakash
    Replies:
    0
    Views:
    428
    Divya Prakash
    Dec 19, 2006
  5. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    346
    Pinegar, Kent T
    Jul 24, 2008
Loading...

Share This Page