[Pyrex] A couple of questions about pyrex

Greg Ewing greg.ewing at canterbury.ac.nz
Tue May 12 14:38:37 CEST 2009


Yingjie Lan wrote:

> 1) Does pyrex support writing iterator classes for collection objects?

Yes. If you give an extension type a __next__ method, it
will get called in response to next(). Also, you can give
your collection class an __iter__ method just as in
Python.

> 2) Why not just
> use 'class MyClass' syntax for pyrex to define an extension?

If you write 'class MyClass' in Pyrex, you get an ordinary
Python class. Since that's the more Python-like behaviour,
it gets the more Python-like syntax.

The difference between 'def' and 'cdef' for functions is
that 'def' functions can be called from Python, whereas
'cdef' ones can't. Again, the more Python-like one gets
Python syntax.

-- 
Greg



More information about the Pyrex mailing list