Hello JoeSox,

If you look at the ArrayList documentation (URL below) you will see that
although it lives in the System namespace, it comes from the
mscorlib.dll assembly.

You will have to add an additional reference in your Python code
(ipy.exe adds references to both of these for you which is why your code
works from the interactive interpreter).

An alternative is adding the references to the assemblies from your
hosting code using LoadAssembly.

http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx

Michael



JoeSox wrote:
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).....


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/


_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to