[IronPython] Engine Scope

JoeSox joesox at gmail.com
Sun Sep 7 18:43:42 CEST 2008


Why can't I access the ArrayList class in the unworking example below?
(Forgive me if this was covered previously but I couldn't find
anything in the archives)

------------working example...------------------
IronPython 2.0 Beta (2.0.0.4000) on .NET 2.0.50727.1433
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference("System")
>>> dir()
['__builtins__', '__doc__', '__name__', 'clr']
>>> from System.Collections import ArrayList
>>> dir()
['ArrayList', '__builtins__', '__doc__', '__name__', 'clr']
>>>
-------------nonworking example...-----------------
            ScriptEngine newengine = ScriptRuntime.Create().GetEngine("py");
            ScriptScope scope = newengine.CreateScope();
            string pycode = @"
import clr
clr.AddReference('System')
from System.Collections import ArrayList";
            ScriptSource source =
newengine.CreateScriptSourceFromString(pycode,
System.Scripting.SourceCodeKind.Statements);

[Exception...]
IronPython.Runtime.Exceptions.ImportException was unhandled
  Message="Cannot import name ArrayList"
  Source="IronPython"
  StackTrace:
       at IronPython.Runtime.Importer.ImportFrom(CodeContext context,
Object from, String name)
       at IronPython.Runtime.Operations.PythonOps.ImportFrom(CodeContext
context, Object module, String name)
       at <module>$1##1(Closure , Scope , LanguageContext )
       at System.Scripting.ScriptCode.InvokeTarget(LambdaExpression
code, Scope scope)
       at System.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression
code, Scope scope)
       at System.Scripting.ScriptCode.Run(Scope scope)
       at System.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
       at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope
scope).....
-- 
Later, JoeSox



More information about the Ironpython-users mailing list