I'm wondering if boost.python allows C++ functionality to be exposed to python after the module has loaded. For example it would be nice if something like this might work:
#include <boost/python.hpp>
int a;
void expose_var() {
boost::python::scope().attr( "a" ) = a;
}
BOOST_PYTHON_MODULE( mod )
{
boost::python::def( "expose_var", expose_var, "Expose an attribute." );
}
Then in python:
import mod
mod.expose_var()
mod.a = 2
With similar code I'm getting an error when I call the equivalent of expose_var():
AttributeError: 'NoneType' object has no attribute '__dict__'
I want to do this as I'm exposing a C++ library that is heavily templated and I don't wish to expose every possible combination of template parameters by default. I'd like to let the python client ask for specific combinations to be exposed at runtime.