[C++-sig] howto check for an attr from c++?
Neal Becker
ndbecker2 at gmail.com
Fri Apr 13 15:45:55 CEST 2007
Stefan Seefeld wrote:
> Neal Becker wrote:
>> I need to check if an object has an attribute from c++.
>>
>> I'm using this low-level approach:
>> (r is an object):
>> if (PyObject_HasAttrString (r.ptr(), "__len__")) {
>>
>> Nothing wrong with that, but is there something in the boost::python api
>> to handle this?
>
> boost::python does provide getattr(), setattr(), and delattr().
>
> HTH,
> Stefan
>
If I call getattr() on a nonexistent attribute, what happens? Does python
throw an exception? (I believe it does). If so, how do I intercept it from
c++? I'm trying to test is an attribute is defined.
More information about the Cplusplus-sig
mailing list