[Pyrex] getattr

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Oct 9 02:07:18 CEST 2007


Martin Field wrote:
> I guess
> the Python version can take 3 arguments (the third being optional)
> whereas the API version only takes 2. Is there some (easy!) way
> of mimicking this behaviour in Pyrex

You could write yourself a function

   cdef object getattr3(object obj, char *attr, object default):
     try:
       return getattr(obj, attr)
     except AttributeError:
       return default

I may include something like this as a Pyrex builtin
if the current behaviour turns out to be too much of a
nuisance.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiem!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+



More information about the Pyrex mailing list