BTW, I've submitted a change recently (it should be already available on
CodePlex) that allows you to simplify the below code to:
ScriptEngine engine = IronPython.Hosting.Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.Execute("import re", scope);
or if you don't need to inspect the scope you can omit it as well:
ScriptEngine engine = IronPython.Hosting.Python.CreateEngine();
engine.Execute("import re");
The Execute method now uses SourceCodeKind.AutoDetect as a default value.
Python parser recognizes this new value and parses the code regardless of
whether it is an expression, a single statement or multiple statements. The
value returned by Execute is either the value of the expression (if the code is
in fact an expression), the value of the last expression statement (if
available) or null otherwise.
You can still use an explicit parameter to CreateScriptSourceFromString that
restricts the kind to expression, statement, etc.
Tomas
From: [email protected]
[mailto:[email protected]] On Behalf Of Curt Hagenlocher
Sent: Tuesday, January 27, 2009 11:17 AM
To: Discussion of IronPython
Subject: Re: [IronPython] import issue
The most likely explanation is that you're missing a reference to
IronPython.Modules.dll.
On Tue, Jan 27, 2009 at 11:14 AM, Janofsky, Steven
<[email protected]> wrote:
Does anyone know why the following gives 'No module named re' error:
ScriptEngine engine = IronPython.Hosting.Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ScriptSource src = engine.CreateScriptSourceFromString( "import re",
Microsoft.Scripting.SourceCodeKind.Statements );
src.Execute( scope );
This transmission may contain information that is privileged, confidential and
exempt from disclosure under applicable law. If you,
[email protected], are not the intended recipient, you are hereby
notified that any disclosure, copying, distribution, or use of the information
contained herein (including any reliance thereon) is STRICTLY PROHIBITED. If
you received this transmission in error, please immediately contact the sender
and destroy the material in its entirety, whether in electronic or hard copy
format. [clavin.webloyalty.com]
_______________________________________________
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