[IronPython] Casting python list type to NET type
dinov at exchange.microsoft.com
Fri May 25 03:39:04 CEST 2007
I'll also add if it's your own application you should be coding to receive IList or IList<T> instead of List. Typically they'll have everything you need and accept a wider range of inputs - e.g. arrays, LinkedList's, normal List's, etc... And if you can get away with it maybe just IEnumerable. Of course if it's someone else's app that's of no use :(.
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Thursday, May 24, 2007 4:35 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Casting python list type to NET type
Filipe Silva wrote:
> Hi all,
> I've an VB.NET application invoking some python functions and I would
> like these functions to return a list type.
To use the return values from other .NET languages like VB.NET and C# I
think you have little choice but to use a .NET collection.
You could make this conditional by wrapping the import in a 'try..
except' and having different behaviour on platforms where the .NET type
is not available (i.e. CPython).
> I've already tried to cast the result from "list" (python) to
> Collection (VB.NET), also to ArrayList and to a simple string array.
> In all cases I receive a cast exception saying that it's not possible
> to make that conversion...
> Is there any NET type that could be directly casted from ironpython list type?
> 1. I can return a String instead of a list, but I would need to parse
> that string inside VB.NET (using some kind of token)
> 2. I've found a solution by importing System.Collections.ArrayList in
> my python script, then using ArrayList object instead of native list
> type, however this way, my script doesn't work in a different engine
> (that one in www.python.org, for instance)
> users mailing list
> users at lists.ironpython.com
users mailing list
users at lists.ironpython.com
More information about the Ironpython-users