[C++-sig] Assign a value to its non-existing attribue, why it did not report a error?

Qinfeng(Javen) Shi shiqinfeng at gmail.com
Mon Oct 16 10:25:08 CEST 2006


Dear All,

I wrapped a class, and get a instance of it, then assign a value to its
non-existing attribue. It should report a error. But it doesn't, and it adds
the non-existing attribue to it.
I want it reports a error when user assign value to a non-existing attribue
mistakely.
Anyone can help me? Thanks in advance.

---------------------c extension---------------
class cover_tree {
   public:
    cover_tree()
    {
    }
};
BOOST_PYTHON_MODULE(hello)
{
  class_<cover_tree>("cover_tree",init<>());
}

>>> c = hello.cover_tree()
>>> c.adf                                                //c  doesn't  have
adf attribute, but still can  assign.
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'cover_tree' object has no attribute 'adf'
>>> c.adf = 1
>>> dir(c)
[
...
 'adf']
>>>
-- 
Qinfeng(Javen) Shi

Research School of Information Sciences and Engineering
Australian National University
Locked Bag 8001
Canberra ACT 2601
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20061016/be035cb4/attachment.htm>


More information about the Cplusplus-sig mailing list