* [EMAIL PROTECTED] wrote:

>> tp_getattro is like defining __getattribute__, i.e. it gets called on
>> every attribute read access. You can use PyObject_GenericGetAttr inside
>> the function to find predefined attributes before applying your own
>> rules.
> 
> Thanks for the reply.  I see and was afraid of that, I don't have a
> predefinded list of attributes.  I want to get them from the C library
> as needed.  Is there another way I should be accessing the data from my
> C lib since it isn't known at compile time?

Well, methods *are* predefined attributes (which just happen to be callable
and bound to the instance).
You can use PyObject_GenericGetAttr like this:

static PyObject *
mytype_getattro(mytypeobject *self, PyObject *name)
{
    PyObject *tmp;

    if (!(tmp = PyObject_GenericGetAttr((PyObject *)self, name))) {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError))
            return NULL;
        PyErr_Clear();
    }
    else
        return tmp;

    /* your code */
}

- or -

explicitly define __getattr__ in tp_methods (instead of tp_getattro), which
only gets called on unknown attributes then.

nd
-- 
die (eval q-qq:Just Another Perl Hacker
:-)

# André Malo, <http://pub.perlig.de/> #
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to