Re: __iter__ and yield
Mike Wyatt <[email protected]> Sun, 19 Sep 2010 22:22:40 -0500
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
--===============0031550479==
Content-Type: multipart/alternative; boundary=001636c5a410c201c40490a86c98
--001636c5a410c201c40490a86c98
Content-Type: text/plain; charset=ISO-8859-1
I figured it out:
def __iter__( cVector2 self ):
return iter( (self.x, self.y) )
On Sun, Sep 19, 2010 at 10:17 PM, Mike Wyatt <[email protected]>wrote:
> 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
>
> Thoughts on how to make this work? I'm using Pyrex 0.9.9 with Python 2.6.
>
--001636c5a410c201c40490a86c98
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I figured it out:<br><br>=A0=A0=A0 def __iter__( cVector2 self ):<br>=A0=A0=
=A0 =A0=A0=A0 return iter( (self.x, self.y) )<br><br><br><div class=3D"gmai=
l_quote">On Sun, Sep 19, 2010 at 10:17 PM, Mike Wyatt <span dir=3D"ltr"><=
;<a href=3D"mailto:[email protected]">[email protected]</a>>=
</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; borde=
r-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I want to write a=
simple iterator for my vector class, but this code isn't compiling:<br=
>
<br>=A0=A0=A0 def __iter__( cVector2 self ):<br>=A0=A0=A0 =A0=A0=A0 yield s=
elf.x=A0=A0=A0=A0=A0 # line 247<br>=A0=A0=A0 =A0=A0=A0 yield self.y<br><br>=
I get this error:<br>
<br>pyrexc src/cVector2.pyx --> src/cVector2.c<br>C:\Development\MikeLib=
\src/cVector2.pyx:247:8: Syntax error in simple statement list<br><br>Thoug=
hts on how to make this work?=A0 I'm using Pyrex 0.9.9 with Python 2.6.=
<br>
</blockquote></div><br>
--001636c5a410c201c40490a86c98--
--===============0031550479==
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
_______________________________________________
Pyrex mailing list
[email protected]
http://lists.copyleft.no/mailman/listinfo/pyrex
--===============0031550479==--