[IronPython] no module named re
Jimmy Schementi
jimmy at schementi.com
Tue Mar 15 17:29:33 CET 2011
Is IronPython.Modules.dll referenced by the host app?
~Jimmy
On Tue, Mar 15, 2011 at 12:22 PM, Slide <slide.o.mix at gmail.com> wrote:
> 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/
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110315/82a682c5/attachment.html>
More information about the Ironpython-users
mailing list