Hello, This is certainly a newbie question but how do I get boost python to wrap a c++ bool type to a python bool type ? Here is what I tried: #include <boost/python.hpp> class Boolean { public: Boolean (bool v) : value(v) {} bool value; }; BOOST_PYTHON_MODULE(boolean) { using namespace boost::python; class_<Boolean>("Boolean", init <bool>() ) .def_readwrite ("value", &Boolean::value); } But the value property is considered as being an 'int' in python (and it's important for me to get the right type). I saw that boost python changelog indicates support for python's bool type but I found no further documentation. Did I miss something ? Nicolas Rougier.
"Nicolas P. Rougier" <Nicolas.Rougier@loria.fr> writes:
Hello,
This is certainly a newbie question but how do I get boost python to wrap a c++ bool type to a python bool type ?
Here is what I tried:
#include <boost/python.hpp> class Boolean { public: Boolean (bool v) : value(v) {} bool value; };
BOOST_PYTHON_MODULE(boolean) { using namespace boost::python; class_<Boolean>("Boolean", init <bool>() ) .def_readwrite ("value", &Boolean::value); }
But the value property is considered as being an 'int' in python (and it's important for me to get the right type). I saw that boost python changelog indicates support for python's bool type but I found no further documentation. Did I miss something ?
It works for me; are you sure your Python actually includes bool support? python -c "print bool" -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams -
Nicolas P. Rougier