[IronPython] v1.1.1: Problem loading assembly, I think
Barry Carr
barrycarr at ixian-software.com
Wed Feb 13 19:36:43 CET 2008
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
More information about the Ironpython-users
mailing list