implementing property in pyrex?

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Thu Mar 27 01:08:10 EST 2003


Mike Rovner wrote:
> Hi all,
> 
> I wonder how to implement property in Pyrex.
> I have getX and setX (C) functions and want to use them for implementing X
> property.

If you're talking about giving an extension type
properties, that's something I've yet to think
about. I believe there's a mechanism for it, but
Pyrex doesn't provide access to it yet.

> If it was pure Python it's easy:
> class A:
>   def getX(self): return 0
>   def setX(self,a): pass
>   X = property(getX,setX)

The best thing I can think of for the moment is
to create a Python subclass of your extension type
and add properties to that.

Note that if you're doing that in your Pyrex file,
you'll have to define the functions outside the
class, e.g.

   cdef class myobjbase:
     ...

   class myobj(myobjbase):
     pass

   def getX(self): return 0
   def setX(self,a): pass
   myobj.X = property(getX,setX)

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list