[Cython] __next__ | not being able to use cpdef

Jelle Feringa jelleferinga at gmail.com
Tue Dec 9 00:20:44 CET 2008


Right, but this isn't any different from looping through a vanilla  
python iterable, right?
Simply typing the number that indexes the iterable already loops twice  
as fast, although obviously its rather trivial code.
Actually, it would be interesting to see if a fast __getitem__ call  
would be available, since that would facilitate writing fast  
specialized iterators easily.

-jelle

On Dec 9, 2008, at 12:42 AM, Aaron DeVore wrote:

> That code example needs a bit of a modification.
>
> class Foo:
>   def __init__(self):
>      self.contents = []
>   # ...code that manipulates self.contents...
>   def chunk(self, n):
>      return iter(self.contents[:n])
>
> On Mon, Dec 8, 2008 at 3:31 PM, Aaron DeVore  
> <aaron.devore at gmail.com> wrote:
>> If there's an internal Python/extension type data structure you could
>> use the iterator from that.
>>
>> class Foo:
>>   def __init__(self):
>>       self.var = []
>>   def __iter__(self):
>>       return iter(self.var)
>>
>> Besides that I can't think of anything.
>>
>> -Aaron


More information about the Cython-dev mailing list