[IronPython] Writing a Python iterator in C#?

Jeff Hardy jdhardy at gmail.com
Fri Apr 30 23:50:26 CEST 2010


I'm trying to implement a Python iterator in C# without also
implementing IEnumerator/IEnumerable (I'm also assuming it's even
possible, of course). When trying to use the class in a for loop (`cu`
is a Cursor instance):

>>> for row in cu:
....      print cu

TypeError: Unable to cast object of type 'Cursor' to type
'IronPython.Runtime.Types.IPythonObject'.

I've got the necessary methods on the class (__iter__() and next())
and I've marked the class with [PythonType]; is there anything else
that needs to be done?

- Jeff



More information about the Ironpython-users mailing list