[IronPython] Using and IronPython 1.1 Dictionary from C#

Michael Foord fuzzyman at voidspace.org.uk
Fri Apr 18 15:39:10 CEST 2008


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



More information about the Ironpython-users mailing list