Re: __iter__ and yield

Stefan Behnel <[email protected]> Thu, 30 Sep 2010 17:27:42 +0200
Newsgroups gmane.comp.python.pyrex
Message-ID <[email protected]>
Mike Wyatt, 20.09.2010 05:17:
> I want to write a simple iterator for my vector class, but this code isn't
> compiling:
>
>      def __iter__( cVector2 self ):
>          yield self.x      # line 247
>          yield self.y
>
> I get this error:
>
> pyrexc src/cVector2.pyx -->  src/cVector2.c
> C:\Development\MikeLib\src/cVector2.pyx:247:8: Syntax error in simple
> statement list

"yield" (i.e. generators and coroutines) is an unsupported feature in both =

Pyrex and Cython. Cython will hopefully get them implemented in the near =

future, although there's no time frame yet. There's a CEP, though:

http://wiki.cython.org/enhancements/generators

Stefan