[IronPython] Iterating over Dictionary<int, str> returns the wrong objects?

Ray Djajadinata rayfd_2000 at yahoo.com
Sun Sep 25 06:28:14 PDT 2005


Hello,

I'm trying to print the contents of a Dictionary<int,
string>. In C# I can do this:

foreach (KeyValuePair<int, string> pair in myDict)
{
    Console.WriteLine(pair.ToString());
}

However, in IP, typing this:

>>> myDict = Dictionary[int, str]()
>>> # ... do stuff here ...

>>> for pair in myDict:
...     print str(pair)
...

or this:

>>> for pair in myDict:
...     print pair.ToString()
...

gives me this:

System.Collections.DictionaryEntry
System.Collections.DictionaryEntry
System.Collections.DictionaryEntry
...

Instead of KeyValuePair<int, string> instances, I was
getting DictionaryEntry-s instead, whose ToString()
method indeed prints the fully qualified name of the
instance (instead of anything meaningful). 

Is there a workaround or I should just wait for the
fix? :)

Thank you!
Ray


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


More information about the users-ironpython.com mailing list