[IronPython] ScriptRuntime.ImportModule("foo") vs. import foo

Dino Viehland dinov at microsoft.com
Fri Oct 29 01:14:14 CEST 2010

Slide wrote:
> I have something like the following code:
> ScriptEngine engine = Python.CreateEngine(); ScriptScope scope =
> engine.CreateScope();
> engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly()); // holds
> the namespace foo
> // the following line throws an exception
> engine.Runtime.ImportModule("foo");
> // the following if executed works fine
> engine.Execute("import foo");
> I'm basically just trying to make the types in my executing assembly available
> to the script. I assumed that the ImportModule would see things that had
> been loaded using LoadAssembly, but this doesn't seem to be the case.
> Does anyone have examples of doing this that works?

I think the problem here is that foo is not a PythonModule - it's a NamespaceTracker
object instead.  ImportModule can currently only support modules.  This could be
made to support namespace trackers - PythonService.ImportModule would need
to be updated to check for a ReflectedNamespace and create a ScriptScope from it.

More information about the Ironpython-users mailing list