Just found out why I can't use PythonInterp shared amongst RuleSet. While the imports are shared and some of the functions each condition/consequence has its own variables passed as locals and no mangling or sharing should occur; hence why we were using Py.runCode(PyCode code, PyObject locals, PyObject globals)  - All variables are passed via a dict andthe locals parameter.

Mark Proctor wrote:
Just tried that, needed to be wrapped in a function otherwise it errors. Gonna get the shared interp thing working.

Mark Proctor wrote:
just chatting to one of the other developers, think we might be able to have a PythonInterpretor for each RuleSet, which should solve this issue. Otherwise whats potentially wrong with doing an exec with the following to emulate an expression:
        String tempText = stripOuterIndention( text );
        if (type.equals("eval"))
            tempText = "return (" + tempText + ")";
        this.text = newText.append(tempText).toString();

Oti wrote:
IMHO you cannot eval an import statement:
  Jython 2.1 on java1.4.2_05 (JIT: null)
  Type "copyright", "credits" or "license" for more information.
  >>> exec("from java.lang import String")
  >>> eval("from java.lang import String")
  Traceback (innermost last):
    File "<console>", line 1, in ?
    File "<string>", line 1  
  	from java.lang import String
  SyntaxError: invalid syntax

so you have to exec the imports first, e.g. like Jim suggested.

Best wishes,

--- Jim Adrig <jim@trampolining.com> wrote:

If you are running these from Java, maybe something like what we do 
will work?

First we 'add_package' since we have the cachedir stuff turned off:

   // for Swing GUI building:
     PySystemState.add_package("java.awt");         // Color, etc.

Then create an interpreter and 'execfile' all our standard 

	  python.execfile( functionFileStream, functionFileName ); // pass
name for parsing errors

The 'functionFileStream' contains lots of things like:

   from javax.swing import JCheckBox, JComboBox, JFrame, JMenuBar, 
JMenu, JMenuItem, JTable, JButton, JOptionPane, JRadioButton, 
   from java.awt import Color, GridLayout, GridBagLayout

On Oct 21, 2004, at 12:45 PM, Mark Proctor wrote:

I'm compiling expressions and blocks for use in our application, to
this we pre-append import statements declared elsewhere. It works
when type is "exec" for blocks but fails when its "eval" for 
expressions. Any ideas of how to get this to work?


   protected Interp(String text, Imports imports, String type)
       this.origininalText = text;
       StringBuffer newText = new StringBuffer();

       if ((imports != null)&&(imports.getImportEntries() != null))
           Iterator it =imports.getImportEntries().iterator();
                     while (it.hasNext())
           {                              ImportEntry importEntry =
(ImportEntry) it.next();
               if (importEntry instanceof PythonImportEntry)
           }                         }
                            this.text = 
newText.append(stripOuterIndention( text )).toString();

       this.node = ( modType ) parser.parse( this.text, type );
       this.code = Py.compile( this.node, "<jython>" );