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

Ray Djajadinata rayfd_2000 at yahoo.com
Mon Sep 19 18:27:06 CEST 2005


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


Hi Ray,

Fredrik already asnwered your generator expression
related question. As
for the arrays,
Here is solution that seems to work:

>>> from System import *
>>> a = Array.CreateInstance(Int32, 10)
>>> a
System.Int32[](0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
>>> r = range(10)
>>> for i in r: a[i] = i
>>> a
System.Int32[](0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

I tried your code snippet, but couldn't identify what
the GetType
function was.

I hope this helps. Again, it is not a perfect solution
and it is one of
many items on our to-do list to make Python built-in
types and .Net
types play better together.

Martin

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Ironpython-users mailing list