Re: [IronPython] Using and IronPython 1.1 Dictionary from C#

2008-04-18 Thread Michael Foord
Michael Foord wrote:
> 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.
>   

What I meant of course was:

new Tuple(new object[2] {col, row})

Which, all in all, is marginally slower than the pure Python solution... :-)

Michael

> Thanks
>
> Michael
>
>   
>> /Simon
>>
>> On Fri, Apr 18, 2008 at 4:39 PM, Michael Foord 
>> <[EMAIL PROTECTED] > 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@lists.ironpython.com 
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>> 
>>
>> ___
>> Users mailing list
>> Users@lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>   
>> 
>
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Using and IronPython 1.1 Dictionary from C#

2008-04-18 Thread Michael Foord
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 
> <[EMAIL PROTECTED] > 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@lists.ironpython.com 
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
> 
>
> ___
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Using and IronPython 1.1 Dictionary from C#

2008-04-18 Thread Simon Dahlbacka
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?

/Simon

On Fri, Apr 18, 2008 at 4:39 PM, Michael Foord <[EMAIL PROTECTED]>
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@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Using and IronPython 1.1 Dictionary from C#

2008-04-18 Thread Michael Foord
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@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com