Reputation: 138
I am new to python c++ interface. I have a dictionary of list and float variables in a python file. Am extracting this python objects into c++ variables. Am able to extract the lists into the vector variables. but am unable to do the same for float type.
this is my dict in dict.py
ATM__INTERPOLATION_CUBE = {
"xOrigin": xOrigin,
"yOrigin": yOrigin,
"zOrigin": zOrigin,
"xEnd" : xEnd,
"yEnd" : yEnd,
"zEnd" : zEnd,
"point_xdensity":point_xdensity,
"point_ydensity":point_ydensity,
"point_zdensity":point_zdensity,
"short_Space_x" : 0.25,
"short_Space_y" : 0.25,
"short_Space_z" : 0.25}
ATM__TYPE = "3D_CUBE"
In my c++ script, I create an object myconfig of python dict type.
python::dict myconfig = ctl->scanConfig("ATM__INTERPOLATION_CUBE", python::dict(), True);
then I create a python list and store each list into a new python list
>
python::list xOrigin_list(myconfig["xOrigin"]);
>python::list yOrigin_list(myconfig["yOrigin"]);
then I extract the python list into my c++ vector variable using loop
> for(init;condt;incr)
> xOrigin.push_back(python::extract <double>(xOrigin_list[i]));
> yOrigin.push_back(python::extract<double>(yOrigin_list[i]));
but the above procedure doesnt work for float or long :(
python::long short_Space_x_fl(myconfig["short_Space_x"]);
> short_Space_x = python::extract<double>(short_Space_x_fl);
it gives me an error. can someone please tell me how to extract the value of type float/long from python and store in c++ double variable?
var.cc:18:11: error: expected unqualified-id before ‘long’
thanks in advance
Upvotes: 2
Views: 1844
Reputation: 138
Only when a list is to be extracted into a vector the above usage works. But for extracting a single data (int, float, long) the extraction syntax is straight forward,
double var_name = python::extract<double>(python_dict_obj["python_key"]);
this will store the float value in dictionary at the given key into the variable of c++
Upvotes: 2