[IronPython] no module named re
Slide
slide.o.mix at gmail.com
Tue Mar 15 17:22:32 CET 2011
I am embedding IronPython in my app to allow some script capabilities.
I have the following code:
_content = content.Trim();
string script = string.Format(@"
import re
def interp(string, variables):
globals = globals()
for item in re.findall(r'\$\(([^{{]*)\)', string):
string = string.replace('$(%s)' % item,
str(eval(item, globals, variables)))
return string
{0}
", _content);
try
{
_engine = Python.CreateEngine();
List<string> searchPaths = new
List<string>(_engine.GetSearchPaths());
searchPaths.Add(
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
_engine.SetSearchPaths(searchPaths);
ScriptSource source =
_engine.CreateScriptSourceFromString(script);
_script = source.Compile();
}
catch(SyntaxErrorException ex)
{
ExceptionOperations eo =
_engine.GetService<ExceptionOperations>();
throw new ScriptedStringParseException(
eo.FormatException(ex), -1);
}
Then later I call:
_script.DefaultScope.SetVariable("context",
GenerateParameters(context));
return _script.Execute<string>();
The problem I am running into is that _script.Execute is that I am
getting an import exception on the "import re"
re is a builtin module, so I am not sure why that is happening, does
the IronPython.Modules.dll need to be in the DLLs directory? I don't
remember having this issue previously.
--
slide-o-blog
http://slide-o-blog.blogspot.com/
More information about the Ironpython-users
mailing list