[IronPython] Re: Why won't these snippets run?
rayfd_2000 at yahoo.com
Mon Sep 19 09:27:06 PDT 2005
Thanks, you spotted the source of the problem. When I
removed GetType() from around Int32, my solution
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):
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
the output was:
<built-in function GetType>
Strange. Since it is an operator in VB, IP shouldn't
even recognize it!
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)
System.Int32(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
>>> r = range(10)
>>> for i in r: a[i] = i
System.Int32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
I tried your code snippet, but couldn't identify what
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.
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the users-ironpython.com