Re: A couple of questions about pyrex
Yingjie Lan <[email protected]> Tue, 12 May 2009 06:04:28 -0700 (PDT)
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
> From: Greg Ewing <[email protected]> > Subject: Re: [Pyrex] A couple of questions about pyrex > To: [email protected] > Cc: [email protected] > 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