[IronPython] Re: Why won't these snippets run?
Martin.Maly at microsoft.com
Mon Sep 19 08:45:14 PDT 2005
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 the GetType
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.
> -----Original Message-----
> From: users-ironpython.com-bounces at lists.ironpython.com
> [mailto:users-ironpython.com-bounces at lists.ironpython.com] On
> Behalf Of Ray Djajadinata
> Sent: Monday, September 19, 2005 12:12 AM
> To: users-ironpython.com at lists.ironpython.com
> Subject: [IronPython] Re: Why won't these snippets run?
> Hi Martin!
> Thanks! I think last time you mentioned that IP already had
> generators--were you referring to 0.9.2 or some other version
> in the future?
> Also... regarding the Array, is there any workaround?
> I tried this:
> from System import Array, Convert, Int32 pyList = [9, 7, 8,
> 4, 6, 3, 6, 8, 4, 1] toBeSorted = Array.CreateInstance(GetType(Int32),
> for index, item in enumerate(pyList):
> toBeSorted.SetValue(item, index)
> but I got this:
> Traceback (most recent call last):
> at __main__.Initialize() in
> C:\temp\workaround.py:line 5
> System.InvalidCastException: Object cannot be stored in an
> array of this type.
More information about the users-ironpython.com