[Pyrex] A couple of questions about pyrex
Yingjie Lan
lanyjie at yahoo.com
Tue May 12 15:04:28 CEST 2009
> From: Greg Ewing <greg.ewing at canterbury.ac.nz>
> Subject: Re: [Pyrex] A couple of questions about pyrex
> To: lanyjie at yahoo.com
> Cc: pyrex at lists.copyleft.no
> Date: Tuesday, May 12, 2009, 4:38 PM
> 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.
>
That's indeed very nice! I like it.
> > 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.
>
So this is why I don't think it is intuitive:
If 'def' defines a function usable by python,
then I would naturally expect 'class' define
a class usable by python too, right?
If 'cdef' define a function hidden from python,
why 'cdef class' define a class for python?
I would expect 'cdef class' define an invisible
class (for internal use of the module) in a
pythonic way (making things easier).
yingjie
More information about the Pyrex
mailing list