Boost logo

Boost :

Subject: [boost] [python] AttributeError
From: Okko Willeboordse (okko.willeboordse_at_[hidden])
Date: 2009-10-27 08:24:34


Running Boost 1.40 ( Windows server 2003/XP, Visual Studio 2008)

Given;

#include<boost/python.hpp>
struct Foo{
       static int bar;
};
int Foo::bar=3;

BOOST_PYTHON_MODULE(foo){
       boost::python::class_<Foo>("Foo",boost::python::init<>())
               .def_readonly("bar",Foo::bar);
}

With Python 2.6.3 and 2.6.4 I get;

>c:\Python26\python.exe -c "import foo"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'Boost.Python.StaticProperty' object attribute '__doc__' is
read-only

Also;
>python
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Boost.Python.StaticProperty' object attribute '__doc__' is
read-only
>>> import foo
>>> dir(foo.Foo)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init
__', '__instance_size__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr_
_', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']

So importing foo for the second time succeeds but foo.Foo holds no bar

With Python < 2.6.3 everything works as expected.

See also
http://mail.python.org/pipermail/cplusplus-sig/2009-August/014747.html


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk