[IronPython] Using and IronPython 1.1 Dictionary from C#

Michael Foord fuzzyman at voidspace.org.uk
Fri Apr 18 16:20:52 CEST 2008


Simon Dahlbacka wrote:
> Actually, I don't really have a clue about this but
>
> Tuple key = new Tuple(new object[col, row]);
>
> seems like it doesn't do what it probably should do, or do you intend 
> to pass a multidimensional array to the Tuple constructor?
:-)

That is probably it.

Thanks

Michael

>
> /Simon
>
> On Fri, Apr 18, 2008 at 4:39 PM, Michael Foord 
> <fuzzyman at voidspace.org.uk <mailto:fuzzyman at voidspace.org.uk>> wrote:
>
>     Hello all,
>
>     I'm trying to use an IronPython (1.1) dictionary from C#, where the
>     dictionary is keyed by tuples.
>
>     I am printing the keys - so I can see that the values I want are
>     in the
>     dictionary, but I can't fetch  them. I have tried various approaches -
>     the problem seems to be that when I create a new Tuple from two
>     integers
>     it isn't recognised as a valid key. Any suggestions/corrections.
>
>     Code below (range is a Python 'Dict'):
>
>
>                System.Console.WriteLine("Keys: {0}", range.keys());
>                for (int row = minRow; row < (maxRow + 1); row++)
>                {
>                    for (int col = minCol; col < (maxCol+1); col++)
>                    {
>                        Tuple key = new Tuple(new object[col, row]);
>                        object val = range.GetValue(key);
>                        if (val != null)
>                            {
>                                try
>                                {
>                                    result =
>     (Double)FloatOps.Add(result, val);
>                                }
>                                catch (Exception e)
>                                {
>                                    System.Console.WriteLine(e);
>                                }
>                            }
>                        else
>                            {
>                                System.Console.WriteLine("No Value for col
>     {0} row {1}", col, row);
>                            }
>                    }
>
>     I'm aware that the cast there is 'dubious', but as my code never
>     reaches
>     it it hasn't been a problem so far!
>
>     Michael Foord
>     _______________________________________________
>     Users mailing list
>     Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   




More information about the Ironpython-users mailing list