[IronPython] Re: Why won't these snippets run?

Martin Maly Martin.Maly at microsoft.com
Mon Sep 19 18:55:43 CEST 2005


I must have mistyped the GetType function the first time around
because IronPython would find it otherwise.

The IronPython's logic to look-up built-in methods finds the method
GetType on the __builtin__ class implementation.

I don't have solution for this yet, but at least we understand what
is going on :)

Thanks!
Martin

> Ray Djajadinata Wrote:
>
> Hi Martin,
> 
> Thanks, you spotted the source of the problem. When I removed 
> GetType() from around Int32, my solution
> works:
> 
> <snippet>
> from System import Array, Convert, Int32
> 
> pyList = [9, 7, 8, 4, 6, 3, 6, 8, 4, 1]
> toBeSorted = Array.CreateInstance(Int32, len(pyList)) for 
> index, item in enumerate(pyList):
>     toBeSorted.SetValue(item, index)
> Array.Sort(toBeSorted)
> </snippet>
> 
> GetType() is a curious thing. It is an operator in VB.NET, 
> which probably got into my snippet from copying the sample 
> for Array.CreateInstance from the .NET SDK documentation 
> somewhere. There wasn't any NameError while running the script though?
> 
> In VB.NET, it returns the Type object for the specified type, 
> so it should return the Type object for Int32 in this case. 
> However, when I did this in my
> script:
> 
> print GetType(Int32)
> print GetType
> 
> the output was:
> 
> IronPython.Objects.OpsReflectedType
> <built-in function GetType>
> 
> Strange. Since it is an operator in VB, IP shouldn't even 
> recognize it!
> 
> Thanks again,
> Ray



More information about the Ironpython-users mailing list