I have a C++ class that is exposed to python with boost python framework.
struct Var
{
Var(std::string name) : name(name), value() {}
std::string const name;
float value;
};
BOOST_PYTHON_MODULE(hello)
{
class_<Var>("Var", init<std::string>())
.def_readonly("name", &Var::name)
.def_readwrite("value", &Var::value);
;
}
Below is the python script using this class:
x = hello.Var("hello")
def print_func():
print(x.value)
Is it possible to access the object x
inside C++ code and assign the value
member variable a value in c++ that is printed when print_func()
is executed in the python script ?
You can change your python and c++ code, as below
Below is the python script using this class: