[C++-sig] Re: boost.python: problem exposing static attribute with specific to_python converter

David Abrahams dave at boost-consulting.com
Sat Jan 8 00:18:59 CET 2005

Baptiste Lepilleur wrote:

> Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import localcegui as cegui
>>>> print "Member:", cegui.TestString().memberFn()
> Member: member
>>>> print "StaticVar:", cegui.TestString.staticVar
> StaticVar:
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: No Python class registered for C++ class class CEGUI::String
>     Changing 'staticVar' type from CEGUI::String to std::string remove this
> error message, so something is really going on with the to_python
> conversion. Why isn't the to_python_converter found ?

According to

   def_readonly(name, pointer_to_data)

is equivalent to

  this->add_static_property(name, make_getter(pointer_to_data));

(modulo a typo, which I'm fixing now).

and according to


"Creates a Python callable object which accepts no arguments and returns
[pointer_to_data] ... converted to_python on demand. If policies is
supplied, it will be applied to the function as described here.
Otherwise, the library attempts to determine whether D is a user-defined
class type, and if so uses reference_existing_object."

reference_existing_object requires a Python wrapper class for the
returned type to exist, so that it can create an instance of that class
containing a pointer to the pointee.  If you want it to use your
converter, you need to get it to use some other policy, like

   .add_static_property("staticVar", make_getter(&TestString::staticVar,

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list