Does this simple case work for you?  It works for me on 1.0, 1.1, and 1.1.1:

Test.cs:
using System;
using IronPython.Hosting;

public class Foo {
    public static void Main(string[]args) {
        PythonEngine pe = new PythonEngine();
        EngineModule module     = pe.CreateModule();
        CompiledCode code = pe.CompileFile(".\\foo.py");

        code.Execute(module);
    }
}

foo.py:

from System.Text.RegularExpressions import *
print dir()
print Regex

The only thing that I could think of that would cause this to break is if we 
somehow failed to add the reference to System.dll - but we do that by default 
so that shouldn't be possible to break.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Barry Carr
Sent: Wednesday, February 13, 2008 10:37 AM
To: [email protected]
Subject: [IronPython] v1.1.1: Problem loading assembly, I think

Hi,

My apologies if this is really obvious but I'm stumped.

The cut down python file below is called from a C# windows form app (.NET 2.0). 
When it runs it
fails and reports: "Name 'Regex' not defined". Stepping through the python code 
shows that it fails
as soon as comes across the first use of the Regex class. I've tried running 
the script with ipy and
I get the same result. I've also tried to import RE. That worked in ipy but 
failed with the same
error when the script was run via the hosting app.


import System
import clr

from System.Text.RegularExpressions import *

class SmartPadToDisplayIT:
     "Description of Class"

     def __init__(self, srcFile, destFile):
         self.template          = []
         self.sourceData        = {}
         self.srcFile           = srcFile
         self.destFile          = destFile
         self.TokenExpression   = Regex("{(.+)}$", RegexOptions.Compiled)

     def Convert(self):
         pass

converter = SmartPadToDisplayIT(sourceFile, destinationFile)
converter.Convert()

the thing the gets me is that this used to work. Has something change between 
1.0 and 1.1 or 1.1 and
  1.1.1? Or have not set up the PythonEngine correctly in my app? Here is the 
C# code that sets up
the  engine:

                public frmConvertSurveys() {
                        InitializeComponent();
             codeBasePath             = 
Platform.GetPath(Assembly.GetExecutingAssembly());
                        EngineOptions opts       = new EngineOptions();
                        opts.ClrDebuggingEnabled = true;
                        opts.ExceptionDetail     = true;
                        opts.ShowClrExceptions   = true;
                        pyEngine                 = new PythonEngine(opts);

                        InitializePythonEngine();
                        CheckEssentialFilesPresent();
                }

                private void InitializePythonEngine() {
                        pyEngine.Import( "site" );
             pyEngine.Import( "clr" );

                        //pyEngine.AddToPath( ".\\" );
                        //pyEngine.AddToPath( codeBasePath );
                }

And, finally, here is the code where the script is called:

private void RunPythonScript() {
                        Dictionary<string, Object> fileParameters = new 
Dictionary<string, Object>();
                        EngineModule module     = pyEngine.CreateModule();
                        //CompiledCode code     = 
pyEngine.CompileFile(".\\SmartPad2DisplayIT.py");
             CompiledCode code = pyEngine.CompileFile(".\\SP2DIY.py");

                        fileParameters.Add( "sourceFile",      string.Empty);
                        fileParameters.Add( "destinationFile", string.Empty);
             try {
                 pbConversion.Maximum = conversionList.Count;
                 pbConversion.Minimum = 0;
                 pbConversion.Value = 0;
                 foreach( ConversionInfo ci in conversionList ) {
                     UpdateFeedback(string.Format("Converting {0} to {1}", 
ci.Source, ci.Destination));
                     fileParameters["sourceFile"] = ci.Source;
                     fileParameters["destinationFile"] = ci.Destination;
                     code.Execute(module, fileParameters);
                     pbConversion.Increment(1);
                 }
             }
             catch( PythonNameErrorException pne ) {
                 UpdateFeedback("*** Python Engine reports ***", "*** " + 
pne.Message + " ***");
             }
             catch( Exception ex ) {
                 UpdateFeedback("*** Unexpected Error ***", "*** " + ex.Message 
+ " ***");
             }
                }

If anyone can shed any light on this I'd be most grateful. Thanks.

Cheers
Barry Carr
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to