[IronPython] Strangeness in list comprehensions in beta 6
Paul Viola
viola at microsoft.com
Sat Apr 22 09:19:27 CEST 2006
Folks,
I defined a C++/CLI IEnumerator<KeyValuePair<int, double> > class (a
sparse matrix class).
When I use it in a comprehension(see below) IP seems to "automatically"
return only the value part of the KeyValuePair.
IronPython 1.0.2302 (Beta) on .NET 2.0.50727.40
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import ShoNS
>>> sss = ShoNS.Array.SparseArray(1000, 1000, 1000)
>>> sss[100, 10] = 1
>>> sss[2, 10] = 2
## Test the IEnumerator directly ##
>>> eee = sss.ColumnElements(10)
>>> eee.MoveNext()
True
>>> eee.Current
[100, 1]
## Type is right!! ##
>>> type(eee.Current)
<type 'KeyValuePair`2'>
## Strange that this does not work ###
>>> [s for s in sss.ColumnElements(10)]
[1.0, 2.0]
## Even worse, this is a bug!!! ##
>>> for s in sss.ColumnElements(10): print s.Key, "->", s.Value
...
Traceback (most recent call last):
File , line 0, in input##203
AttributeError: 'float' object has no attribute 'Key'
>>>
Thanks,
Paul Viola
Senior Researcher
Microsoft Research
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060422/6ee0d118/attachment.html>
More information about the Ironpython-users
mailing list